【问题标题】:Crashlytics doesn't work in iOS keyboard extensionCrashlytics 在 iOS 键盘扩展中不起作用
【发布时间】:2015-06-25 16:32:23
【问题描述】:

我正在使用最新版本的 FabricFabric/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

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

【问题讨论】:

    标签: ios crashlytics ios-keyboard-extension


    【解决方案1】:

    发布此消息几分钟后,我发现实际上在[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
    

    【讨论】:

      【解决方案2】:

      Clashlytics 以 BundleIdentidfier 为特征,它似乎可以工作。 主应用,应用扩展是不同的Bundle Identifier。

      在同一个 Bundle Identifier 和 Keyboard App 中,您将创建另一个新项目。如果将键盘应用扩展的图标设置为新项目,那就更好了。图标将用于 Clashlytics 网页。

      在新创建的项目中安装 crashlytics,并完成。 现在,它也适用于原始项目。 完成后,您可以删除新项目。

      我就是这样工作的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-09-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多