AppReports 1.0.5

AppReports 1.0.5

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2019年3月
SPM支持SPM

ProVir维护。



  • 作者
  • ViR (Vitaliy Korotkiy)

ProVir AppReports

CocoaPods Compatible Carthage Compatible Platform License

用于报告事件和错误的辅助框架。用Swift编写和使用。您可以使用Swift编写支持Objective-C作为此类包装器的辅助器。

此框架是线程安全的。

功能

  • 带有自定义类型的报告事件的通用布局。
  • 报告错误的通用布局。

要求

  • iOS 8.0+
  • Xcode 10.2
  • Swift 5.0

通信

  • 如果您需要帮助,请访问 provir.ru
  • 如果您发现了一个错误,请提交问题。
  • 如果您有功能请求,请提交问题。
  • 如果想要贡献,请提交pull请求。

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它

$ gem install cocoapods

需要 CocoaPods 1.6.0+ 才能构建 AppReports 1.0.0+。

要使用 CocoaPods 在您的 Xcode 项目中集成 AppReports,请在您的 Podfile 中指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

target '<Your Target Name>' do
  pod 'AppReports', '~> 1.0'
end

然后,运行以下命令

$ pod install

Carthage

Carthage 是一个分布式的依赖管理器,它构建您的依赖并提供二进制框架。

您可以使用以下命令使用 Homebrew 安装 Carthage

$ brew update
$ brew install carthage

要使用 Carthage 在您的 Xcode 项目中集成 AppReports,请在您的 Cartfile 中指定它

github "ProVir/AppReports" ~> 1.0

运行 carthage update 构建框架,并将构建的 AppReports.framework 拖动到您的 Xcode 项目中。

手动

如果您不希望使用上述任何依赖管理器,您可以将 ProVirAppReports 手动集成到项目中。

将项目中的 AppReports 目录中的文件复制。


用法

要使用框架,您需要

  1. 使用别名或从 AppReportsCore 继承(记录日志,但没有错误和事件),AppReportsGenericError(仅记录日志和错误)或 AppReportsGeneric(完整的功能 - 日志、错误和事件)。
  2. 如果您需要发送错误,请创建自己的错误类型或使用预定义的 AppReportsErrorData 结构。
  3. 如果您需要发送事件,请创建自己的事件类型。通常这可以是枚举或结构体。
  4. 使用您创建的类或别名 AppReports 的参数执行 AppReportsCore.setup()

注意:为了使用库,请记住在每个文件中包含它:import AppReports

可选的 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)
    }
}

使用 AppReportsErrorData 作为类型错误数据的 AppReportErrorsDestionation 示例

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)
        }
    }
}

使用自定义类型事件数据的 AppReportEventsDestionation 示例

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)
    }
}

设置 AppReports 的示例

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
        }
    }
}

使用 AppReports 的示例

import AppReports

func testLogs() {
    AppReports.log("Test log")
}

func testEvent() {
    AppReports.shared.reportEvent(.oneType(.one))
}

func testError(_ error:Error) {
    AppReports.shared.reportError(error)
}

作者

ViR (Виталий Короткий)

许可证

ProVir AppReports 在MIT许可证下发布。查看CONTRIBUTORS以获取详细信息。