iOS App Extension SDK 使用指南
注意:本SDK已停止维护,不再提供新增服务,如有诉求请咨询Bugly小助手
接入前准备
在接入sdk之前,请务必认真阅读《开发者合规指南》和《Bugly SDK个人信息保护规则》
初始化SDK
导入头文件
在工程的InterfaceController.h中导入头文件
#import <BuglyExtension/CrashReporterLite.h>
如果是其它类型的 Extension,请在入口的 ViewController.h 中导入
如果是 Swift 工程,请在对应的 bridging-header.h 中导入
初始化 BuglyExtension SDK
Watch Extension
watchOS 1.0版本,watchOS 2.0请参考watchOS SDK 使用指南
在工程InterfaceController.m的- (instancetype)init方法中初始化 Bugly Extension SDK
如果 Xcode 初始模板没有此方法,直接复制以下代码粘贴即可
- Objective-C
- (instancetype)init {
self = [super init];
if (self) {
[CrashReporterLite startWithApplicationGroupIdentifier:@"此处替换为您的 App Group Identifier"];
}
return self;
}
- Swift
override init() {
CrashReporterLite.startWithApplicationGroupIdentifier("此处替换为您的 App Group Identifier")
super.init()
}
如果 Apple Watch App 中还有 Glance 或 Notification 交互实现,则需在各自的入口 Controller 中添加上述代码
其它类型 Extension
其它类型的 iOS Extension,如 Today Extension,Share Extension 等,请在对应的ViewController.m的- (instancetype)initWithCoder方法中初始化
如果 Xcode 初始模板没有此方法,直接复制以下代码粘贴即可
- Objective-C
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[CrashReporterLite startWithApplicationGroupIdentifier:@"此处替换为您的 App Group Identifier"];
}
return self;
}
- Swift
required init(coder aDecoder: NSCoder) {
CrashReporterLite.startWithApplicationGroupIdentifier("此处替换为您的 App Group Identifier")
super.init(coder: aDecoder)
}
Containning App 中的初始化
BuglyExtension SDK 依赖于 Bugly iOS SDK 1.2.9 及以上版本
如需支持 Extension 的异常捕获,在 Host App 中的初始化方法需要变更为以下方法:
- Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[CrashReporter sharedInstance] installWithAppId:@"此处替换为你的AppId" applicationGroupIdentifier:@"此处替换为你的App Group标识符"];
return YES;
}
- Swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
CrashReporter.sharedInstance().installWithAppId("此处替换为你的AppId" applicationGroupIdentifier:"此处替换为你的App Group标识符")
return true
}
至此,恭喜您的工程已经成功集成 BuglyExtension SDK,接下来编译并运行您的工程吧