我已经安装了从可可荚版本3.14
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:oneTrackId];
代码行中的iOS 10崩溃
NSString *user_id = [tracker get:kGAIUserId];
由于“NSInvalidArgumentException”异常导致错误*终止应用程序,原因:'* -GAITrackerModel valueForKey::尝试检索一个零键的值‘
发布于 2016-08-11 16:43:01
苹果在iOS 10中改变了iOS 10中的valueForKey:
方法行为。以前用参数nil
调用valueForKey:
会导致用nil
调用valueForUndefinedKey:
,如果这个方法没有被覆盖,它就会失败。但现在,如果没有这个电话,它马上就会失败。
GAITrackerModel
覆盖了valueForUndefinedKey:
,不管输入参数如何,它都返回零。
我可以提供方法swizzling,并将以前的行为恢复为临时解决方案(Google应该修复这个问题,这段代码还没有准备好生产,但在此之前):
#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
发布于 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
https://stackoverflow.com/questions/38850192
复制相似问题