Reports events and errors helper framework. Write and use for swift. You can write helper on swift with support objc as wrapper for this class.
This framework is safe thread.
- General layout for reports event with custom type.
- General layout for reports errors.
- iOS 8.0+
- Xcode 10.2
- Swift 5.0
- If you need help, go to provir.ru
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
CocoaPods 1.6.0+ is required to build AppReports 1.0.0+.
To integrate AppReports into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target '<Your Target Name>' do
pod 'AppReports', '~> 1.0'
end
Then, run the following command:
$ pod install
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate AppReports into your Xcode project using Carthage, specify it in your Cartfile
:
github "ProVir/AppReports" ~> 1.0
Run carthage update
to build the framework and drag the built AppReports.framework
into your Xcode project.
If you prefer not to use any of the aforementioned dependency managers, you can integrate ProVirAppReports into your project manually.
Copy files from directory AppReports
in your project.
To use the framework, you need:
- Use alias or inherit from
AppReportsCore
(logs, but without errors and events),AppReportsGenericError
(logs and errors only) orAppReportsGeneric
(full - logs, errors and events). - If you need to send errors, create your own type for errors or use the ready-made struct of
AppReportsErrorData
. - If you need to send events, create your own type for events. Usually this is enum or struct.
- Perform
AppReportsCore.setup()
with parameters of the created you class or alias AppReports.
Note: To use the library, remember to include it in each file: import AppReports
.
import Crashlytics
import AppReports
private class AppReportsHelper: AppReportsCoreHelper {
func logAdded(_ newStr: String, currentLog: String) {
//Crashlytics
CLSLogv("%@", getVaList([newStr]))
}
func additionalValuesChanged(key: String, newValue: Any?, currentDict: [String : Any]) {
Crashlytics.sharedInstance().setValue(newValue, forKey: key)
}
}
import Crashlytics
import AppReports
class AppReportsFabricErrors: AppReportErrorsDestionation<AppReportsErrorData> {
override func reportError(appReport: AppReportsCore, data: AppReportsErrorData, logs: String, additionalValues: [String : Any]) {
if let error = data.error {
Crashlytics.sharedInstance().recordError(error, withAdditionalUserInfo: data.userInfo)
}
}
}
import Fabric
import AppReports
enum AppReportsEvent {
enum SubEventOne {
case one
case two
}
enum SubEventTwo {
case one
case two
}
case oneType(SubEventOne)
case twoType(SubEventTwo)
case threeType(String)
case fourType
}
class AppReportsFabricEvents: AppReportEventsDestionation<AppReportsEvent> {
override func reportEvent(appReport: AppReportsCore, data: AppReportsEvent, additionalValues: [String : Any]) {
let eventName:String
switch data {
case .oneType(let subEvent):
switch subEvent {
case .one:
eventName = "One.one"
case .two:
.....
}
...
}
Answers.logCustomEvent(withName: eventName, customAttributes: additionalValues)
}
}
import AppReports
typealias AppReports = AppReportsGeneric<AppReportsEvent, AppReportsErrorData>
extension AppReportsGeneric where TypeEventData == AppReportsEvent, TypeErrorData == AppReportsErrorData {
static func createAppReports() {
let helper = AppReportsHelper()
setup(AppReports(settings: AppReportsCore.SettingsCore(),
helper: helper,
eventsDestionations: [AppReportsFabricEvents()],
errorsDestionations: [AppReportsFabricErrors]))
}
static var shared:AppReports {
if let instance = coreShared as? AppReports {
return instance
} else {
createAppReports()
return coreShared as! AppReports
}
}
}
import AppReports
func testLogs() {
AppReports.log("Test log")
}
func testEvent() {
AppReports.shared.reportEvent(.oneType(.one))
}
func testError(_ error:Error) {
AppReports.shared.reportError(error)
}
ProVir AppReports is released under the MIT license. See LICENSE for details.