Crashlytics在iOS键盘扩展中不起作用 [英] Crashlytics doesn't work in iOS keyboard extension

查看:129
本文介绍了Crashlytics在iOS键盘扩展中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新版本的FabricFabric/Crashlytics cocoapods(因此,根据调试器输出,版本为3.0.8)将Crashlytics集成到iOS键盘扩展中.最近,它只是停止报告键盘扩展的崩溃信息.我已经检查了初始化Crashlytics的代码和项目的Crashlytics脚本构建阶段,两者均已执行(构建阶段位于键盘扩展的目标中).

I'm using the latest version of the Fabric and Fabric/Crashlytics cocoapods (so, version 3.0.8 according to the debugger output) to integrate Crashlytics into an iOS keyboard extension. Recently, it simply stopped reporting crashes from the keyboard extension. I've checked both my code which initializes Crashlytics and the Crashlytics script build phase of my project, both are executed (and the build phase is in my keyboard extension's target).

很难确定这是否相关,但是当我运行该应用程序时,我看到Crashlytics尝试提交崩溃,

It's hard to tell if this is related, but when I run the app I see Crashlytics try to submit crashes,

[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

然后读取相应数量的邮件

and then a corresponding number of messages reading

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中的错误.最新版本的更新日志中提到了后台任务的问题

leading me to believe that this is a bug in Crashlytics. The changelog for the latest version mentions an issue with background tasks

Fixed an issue that would incorrectly default to enabling NSURLSession background uploads in extensions

这可能相关吗?有没有人遇到并解决了这个问题?

could this be related? Has anyone encountered and resolved this issue?

推荐答案

发布此消息后的几分钟,它对我来说实际上是在[NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:]上设置了一个符号断点,而不是我过去尝试过的方法.在Crashlytics代码中命中了断点.

A few minutes after posting this, it occcured to me to actually set a symbolic breakpoint on [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:] instead of on the methods I had tried in the past. The breakpoint was hit in Crashlytics code.

要解决此问题,我用一种返回默认配置的方法来修饰backgroundSessionConfigurationWithIdentifer:.实现如下:

To fix this, I swizzled backgroundSessionConfigurationWithIdentifer: with a method that returns the default configuration. Implementation is below:

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

这篇关于Crashlytics在iOS键盘扩展中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆