首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场

iOS10
EN

Stack Overflow用户
提问于 2016-08-09 12:03:40
回答 2查看 1.6K关注 0票数 2

我已经安装了从可可荚版本3.14

代码语言:javascript
运行
复制
id<GAITracker> tracker =  [[GAI sharedInstance] trackerWithTrackingId:oneTrackId];

代码行中的iOS 10崩溃

代码语言:javascript
运行
复制
NSString *user_id = [tracker get:kGAIUserId];

由于“NSInvalidArgumentException”异常导致错误*终止应用程序,原因:'* -GAITrackerModel valueForKey::尝试检索一个零键的值‘

EN

回答 2

Stack Overflow用户

发布于 2016-08-11 16:43:01

苹果在iOS 10中改变了iOS 10中的valueForKey:方法行为。以前用参数nil调用valueForKey:会导致用nil调用valueForUndefinedKey:,如果这个方法没有被覆盖,它就会失败。但现在,如果没有这个电话,它马上就会失败。

GAITrackerModel覆盖了valueForUndefinedKey:,不管输入参数如何,它都返回零。

我可以提供方法swizzling,并将以前的行为恢复为临时解决方案(Google应该修复这个问题,这段代码还没有准备好生产,但在此之前):

代码语言:javascript
运行
复制
#import <objc/runtime.h>

void SwizzleInstanceMethod(Class classToSwizzle, SEL origSEL, Class myClass, SEL newSEL) {
  Method methodToSwizzle = class_getInstanceMethod(classToSwizzle, origSEL);
  Method myMethod = class_getInstanceMethod(myClass, newSEL);
  class_replaceMethod(classToSwizzle, newSEL, method_getImplementation(methodToSwizzle), method_getTypeEncoding(methodToSwizzle));
  class_replaceMethod(classToSwizzle, origSEL, method_getImplementation(myMethod), method_getTypeEncoding(myMethod));
}

@interface FixGoogleSDKiOS10 : NSObject

@end

@implementation FixGoogleSDKiOS10

+ (void)load {
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    SwizzleInstanceMethod([NSObject class], @selector(valueForKey:), [self class], @selector(yb_valueForKey:));
  });
}

- (nullable id)yb_valueForKey:(NSString *)key {
  if (!key) {
    return [self valueForUndefinedKey:key];
  }
  return [self yb_valueForKey:key];
}

@end
票数 3
EN

Stack Overflow用户

发布于 2016-09-12 16:48:28

我们已经发布了SDK的3.17版本。它包含了许多改进和错误修复,包括针对此问题的修复。

CocoaPod:https://cocoapods.org/pods/GoogleAnalytics

SDK下载:https://developers.google.com/analytics/devguides/collection/ios/v3/sdk-download

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38850192

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档