注意:BuglyExtension 依赖于 Bugly iOS SDK 1.2.9 及以上版本
BuglyExtension 提供两种集成 SDK 的方式供 iOS 开发者选择
-
CocoaPods
-
手动集成
在工程的 Podfile 里对应的 Extension Target 中添加以下代码
pod 'BuglyExtension'示例:
target 'ExtensionPodTest WatchKit Extension' do
pod 'BuglyExtension'
end保存并运行pod install,然后用后缀为.xcworkspace的文件打开工程
关于CocoaPods的更多信息请查看 CocoaPods官方网站
-
下载并解压 iOS Extension SDK
-
拖拽
BuglyExtension.framework文件到 Xcode 工程内 (如下图)- 请勾选
Copy items if needed选项 - 如有多个 Extension Targets ,则一一进行勾选
- 请勾选
在工程的InterfaceController.h中导入头文件
#import <BuglyExtension/CrashReporterLite.h>
如果是其它类型的 Extension,请在对应的入口ViewController.h中导入
如果是 Swift 工程,请在对应的bridging-header.h中导入
在工程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中添加上述代码。
其它类型的 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)
}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
}