[英]Crashlytics doesn't work in iOS keyboard extension
我正在使用Fabric
和Fabric/Crashlytics
cocoapods的最新版本(因此,根据调试器输出,版本为3.0.8)将Crashlytics集成到iOS键盘扩展中。 最近,它只是停止报告键盘扩展的崩溃信息。 我已经检查了初始化Crashlytics的代码和项目的Crashlytics脚本构建阶段,两者都已执行(构建阶段在键盘扩展的目标中)。
很难确定这是否相关,但是当我运行该应用程序时,我看到Crashlytics尝试提交崩溃信息,
[Crashlytics:Crash:Reports] Submitting async /var/mobile/Containers/Data/PluginKitPlugin/[some-numbers]/Library/Caches/com.crashlytics.data/com.myCompnay.myApp.extension/v3/prepared/[some-more-numbers-idk-if-they're-supposed-to-be-secret].multipartmime
然后读取相应数量的邮件
2015-06-25 09:22:33.063 com.myCompany.myApp.extension[5975:1649412] Attempted to create a task in a session that has been invalidated
使我相信这是Crashlytics中的错误。 最新版本的变更日志提到了后台任务问题
Fixed an issue that would incorrectly default to enabling NSURLSession background uploads in extensions
这可能相关吗? 有没有人遇到并解决过这个问题?
发布此消息后几分钟,我发现实际上是在[NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:]
上设置了一个符号断点,而不是我过去尝试过的方法。 在Crashlytics代码中命中了断点。
为了解决这个问题,我使用了一种返回默认配置的方法来解决backgroundSessionConfigurationWithIdentifer:
。 实现如下:
static Class URLSessionClass;
@implementation NSURLSessionConfiguration (FixCrashlyticsBug)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
URLSessionClass = object_getClass((id)self);
});
}
+ (NSURLSessionConfiguration *)defaultSessionConfigurationWithIdentifier:(NSString *)__unused identifer {
return [self defaultSessionConfiguration];
}
@end
@implementation CrashlyticsInterfaceManager
+ (void)startCrashlyticsFromExtension {
//Do the swizzle here instead of in load, so we don't do it in the container app as well
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
SEL originalSelector = @selector(defaultSessionConfigurationWithIdentifier:);
SEL swizzledSelector = @selector(backgroundSessionConfigurationWithIdentifier:);
Class class = URLSessionClass;
Method swizzledMethod = class_getClassMethod(class, swizzledSelector);
Method originalMethod = class_getClassMethod(class, originalSelector);
BOOL didAddMethod = class_addMethod(class,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
[Crashlytics startWithAPIKey:@"MyAPIKey"];
});
}
@end
Clashlytics由BundleIdentidfier区分,它似乎可以工作。 主应用程序,App Extension是一个不同的捆绑包标识符。
在同一个Bundle Identifier和Keyboard App中,您将创建另一个新项目。 如果将Keyboard App Extension的图标设置为新项目,那会更好。 图标将在Clashlytics网页中使用。
将clashlytics安装到新创建的项目中,然后完成。 现在,它也可以与原始项目一起使用。 完成后,您可以删除新项目。
我以这种方式工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.