Crashlife 1.0.2

Crashlife 1.0.2

Daniel DeCovnickDave Schukin维护。



Crashlife 1.0.2

  • 作者:
  • Buglife

Platform CocoaPods Compatible Carthage compatible License Twitter

Crashlife 是一款优秀的 iOS 应用崩溃报告 SDK 和 Web 平台。以下是其工作原理

  1. 您的应用程序崩溃并重新启动
  2. Crashlife 将崩溃报告发送到 Crashlife 网络仪表板
  3. 没有第 3 步。

您也可以在此处找到 Crashlife for Androidhere


主要特性
📖 开源
🏃🏽‍♀️ 快速且轻量级
📜 自定义属性
ℹ️ 捕获的足迹和日志,包括信息/警告/错误级别
👩🏽‍💻 使用 Objective-C 编写,完全支持 Swift

安装

CocoaPods

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

pod 'Crashlife'

然后,运行以下命令

$ pod install

Carthage

将以下行放入您的 Cartfile

github "Buglife/Crashlife-iOS"

现在运行 carthage update。然后,将 Carthage/build 文件夹中的 Crashlife.framework 拖放到您的项目中。有关详细/更新的说明,请参阅Carthage README

代码

  1. 将Crashlife框架的头文件导入您的应用程序委托。

    // Swift
    import Crashlife
    // Objective-C
    #import <Crashlife/Crashlife.h>
  2. 将以下代码添加到应用程序委托的application:didFinishLaunchingWithOptions:方法中。

    // Swift
    Crashlife.shared.start(withAPIKey: "YOUR_API_KEY_HERE")
    // Objective-C
    [[Crashlife sharedCrashlife] startWithAPIKey:@"YOUR_API_KEY_HERE"];

    务必用您自己的API密钥替换YOUR_API_KEY_HERE

  3. 构建并运行您的应用程序,然后使其崩溃(希望是故意地!)请注意,如果应用程序在附加调试器的情况下启动,则崩溃报告器不会在大多数崩溃中激活。

  4. 重启后,您的崩溃将被提交;然后访问Crashlife网页仪表板。

使用方法

崩溃报告

初始化后,Crashlife将监视未捕获的异常(C++,ObjC),以及Mach和POSIX信号。崩溃报告将保存在磁盘上,并在下一次启动时发送。如果无法提交崩溃报告,它将保存在磁盘上,直到启动时可以发送。

此外,Crashlife还支持将捕获的异常以及错误、警告和信息消息作为单独的事件记录到网页仪表板。

捕获异常报告

Crashlife可以记录包含完整堆栈跟踪的捕获异常。从您的捕获块中调用

// Swift
Crashlife.shared.logException(anNSException)
// Objective-C
[[Crashlife sharedCrashlife] logException:anNSException];

您还可以传递一个新的(尚未抛出)异常,但为了性能原因,它将不包含堆栈跟踪。Crashlife将尝试立即发送异常事件,并在无法发送的情况下将其缓存。

错误/警告/信息事件

Crashlife支持记录您选择的严重性的消息:崩溃、错误、警告和信息。

// Log an NSError
Crashlife.shared.logErrorObject(anNSError)

// Log an error
Crashlife.shared.logError("An error occurred: ...")

// Log a warning
Crashlife.shared.logWarning("Warning: doing something dangerous...")

// Log an informational message
Crashlife.shared.logInfo("Note: something weird is going on...")
// Objective-C
[[Crashlife sharedCrashlife] logErrorObject:error];

[[Crashlife sharedCrashlife] logError:@"An error occurred..."];

[[Crashlife sharedCrashlife] logWarning:@"Warning: doing something dangerous..."];

[[Crashlife sharedCrashlife] logInfo:@"Note: something weird is going on..."];

足迹

为了帮助重现崩溃,您可以通过包含指向崩溃或错误代码路径的足迹来实现。这些足迹可以包含它们自己的属性以避免自定义属性的杂乱。除非提交了报告,否则这些足迹不会发送到 Crashlife 网络仪表板。

// Leave a footprint with no metadata
Crashlife.shared.leaveFootprint("User navigated to screen 2")

// Leave a footprint with metadata
var attributes = [:]
attributes["Developer"] = "You"
attributes["App"] = "Awesome"
Crashlife.shared.leaveFootprint("User did something else", withMetadata:attributes)
// Objective-C
[[Crashlife sharedCrashlife] leaveFootprint:@"User navigated to screen 2"];

NSDictionary<NSString *, NSString *> *attributes = @{@"Developer" : @"You", @"App" : @"Awesome"};
[[Crashlife sharedCrashlife] leaveFootprint:@"User did something else" withMetadata:attributes];

自定义属性

添加自定义属性

您可以在崩溃报告和日志事件中包含自定义属性(即键值对),如下所示

// Swift
Crashlife.shared.setStringValue("2Pac", forAttribute:"Artist")
Crashlife.shared.setStringValue("California Love", forAttribute:"Song")
// Objective-C
[[Crashlife sharedCrashlife] setStringValue:@"2Pac" forAttribute:@"Artist"];
[[Crashlife sharedCrashlife] setStringValue:@"California Love" forAttribute:@"Song"];


#### Removing attributes

To clear an attribute, set its value to nil.

```swift
Crashlife.shared.setStringValue(nil, forAttribute:"Artist")
[[Crashlife sharedCrashlife] setStringValue:nil forAttribute:@"Artist"];

用户识别

您可以设置代表用户姓名、数据库 ID 或其他标识符的字符串

let username = ... // the current username
Crashlife.shared.setUserIdentifier(username)
NSString *username = ...;
[[Crashlife sharedCrashlife] setUserIdentifier:username];

要求

  • Xcode 8 或更高版本
  • iOS 9 或更高版本

贡献

目前我们没有贡献指南,但您可以自由提交拉取请求和在 GitHub 上提交问题!

许可证

Copyright (C) 2019 Buglife, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://apache.ac.cn/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.