Errbit iOS Notifier被设计为给开发者即时通知他们应用中发生的错误。只需几行代码,您的应用遇到崩溃或异常时将自动报告。这些报告将直接发送到您自己的Errbit副本,您可以查看堆栈跟踪、设备类型、应用版本等信息。
要了解这可能会如何帮助您,请查看这个屏幕录像。如果您有任何问题或需要支持,请访问Errbit iOS支持
该通知器需要iOS 6.0或更高版本的iOS项目。
此项目最初是从Airbrake iOS Notifier分叉的。
通知器处理所有未处理的异常,以及一系列Unix信号
SIGABRT
SIGBUS
SIGFPE
SIGILL
SIGSEGV
SIGTRAP
为了在崩溃时正确地符号化调用堆栈,使用通知器构建的应用程序在编译时不应该剥离它们的符号信息。如果未设置建议的这些设置,则二进制文件中的帧将由十六进制返回地址显示,而不是可读的字符串。可以使用atos
对这些十六进制返回地址进行符号化。有关符号化和这些构建设置的更多信息,请参阅Apple的开发者文档。以下是可以控制代码剥离的设置
这些说明是使用Xcode 4.4+编写的。
"NOTICE_TITLE" = "Crash Report";
"NOTICE_BODY" = "%@ has detected unreported crashes, would you like to send a report to the developer?";
"SEND" = "Send";
"DONT_SEND" = "Don't Send";
"ALWAYS_SEND" = "Always Send";
在您使用通知器时,您将主要与 EBNotifier
类进行交互。它所有的方法和属性,以及 EBNotifierDelegate
协议在各自的头文件中都有文档。请仔细阅读头文件以完整了解库。
要运行通知器,您只需完成两个步骤。首先,将 EBNotifier
头文件导入到您的应用程序代理中
#import <ErrbitNotifier/EBNotifier.h>
接下来,在 application:didFinishLaunchingWithOptions:
的开头调用启动通知器方法
[EBNotifier startNotifierWithAPIKey:@"key"
serverAddress:@"errbit.server.com"
environmentName:EBNotifierAutomaticEnvironment
useSSL:YES // only if your account supports it
delegate:self];
API 密钥参数期望您的 Airbrake 项目 API 密钥。您提供的环境名称将用于在 Airbrake 网络界面中对收到的崩溃报告进行分类。通知器提供了多个工厂环境名称,您可以使用。
EBNotifierAutomaticEnvironment
环境将根据 DEBUG
宏的存在将环境设置为发布或开发
从通知器的 3.0 版本开始,您可以在任何时间记录自己的异常。
@try {
// something dangerous
}
@catch (NSException *e) {
[EBNotifier logException:e];
}
为了测试通知器在您的应用程序内部是否工作正常,提供了一个简单的测试方法。此方法引发一个异常,捕获它,并将其报告得好像发生了真实的崩溃。将此代码添加到 application:didFinishLaunchingWithOptions:
以测试通知器
[EBNotifier writeTestNotice];
如果使用 DEBUG
宏表示开发构建,则通知器将像实际崩溃报告一样将通知和错误记录到控制台,以帮助查看更多详细信息。
在尝试了解此库的工作方式时,以下是一些信息
~/Library/DiagnosticReports/
是存储所有崩溃报告的位置~/Library/Application Support/YOURAPP/Errbit Notices
是在它们发送到服务器之前存储您的 Errbit 通知的位置。您可以通过 [EBNotifier pathForNoticesDirectory]
以编程方式访问此路径[[EBNotifier postNoticesWithPaths:[EBNotifier pathsForAllNotices]]
EBNotifierDelegate
协议允许您响应通知器内部正在执行的操作,并提供运行时自定义。从通知器的 3.0 版本开始,匹配的一组通知都会发布到 NSNotificationCenter
。EBNotifierDelegate
协议中所有的代理方法都有文档,文档位于 EBNotifierDelegate.h
。这里只列出其中的一些方法
MyAppDelegate.h
#import <ErrbitNotifier/EBNotifier.h>
@interface MyAppDelegate : NSObject <UIApplicationDelegate, EBNotifierDelegate>
// your properties and methods
@end
MyAppDelegate.m
@implementation MyAppDelegate
// your other methods
#pragma mark - notifier delegate
/*
These are only a few of the delegate methods you can implement.
The rest are documented in ABNotifierDelegate.h. All of the
delegate methods are optional.
*/
- (void)notifierWillDisplayAlert {
[gameController pause];
}
- (void)notifierDidDismissAlert {
[gameController resume];
}
- (NSString *)titleForNoticeAlert {
return @"Oh Noes!";
}
- (NSString *)bodyForNoticeAlert {
return @"MyApp has detected unreported crashes, would you like to send a report to the developer?";
}
@end