Bugsnag:升级到版本5时缺少函数mergeWith

时间:2016-02-28 13:14:01

标签: ios objective-c bugsnag

我的iOS正在使用Bugsnag,我正在尝试将其从4.1.0升级到版本5.

新SDK破坏了版本4.x中可用的功能:

RuntimeExceptions

参数的类型为[[[Bugsnag configuration] metaData] mergeWith:parameters];

我在SDK中找不到任何替代品,除了:

NSDictionary

但它不提供- (void)addAttribute:(NSString*)attributeName withValue:(id)value toTabWithName:(NSString*)tabName 可能是value本身的相同功能。此外,它还会在每次添加时调用NSDictionary(非常低效)。

1 个答案:

答案 0 :(得分:2)

查看Github repository并查看版本之间[self.delegate metaDataChanged:self]之间的差异后,我找到了恢复此功能的方法。我写了一个扩展课程的类别:

BugsnagMetaData

此函数能够像以前一样接受包含NSDictionary的NSDictionary,并仅在需要时有效地调用@interface BugsnagMetaData (BugsnagExtension) - (void)mergeWith:(NSDictionary *)data; @end @implementation BugsnagMetaData (BugsnagExtension) - (void)mergeWith:(NSDictionary *)data { @synchronized(self) { NSString *customDataKey = @"customData"; [data enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) { NSMutableDictionary *destination = [self getTab:customDataKey]; if ([value isKindOfClass:[NSDictionary class]]) { NSDictionary *source = value; [source enumerateKeysAndObjectsUsingBlock:^(id sourceKey, id sourceValue, BOOL *stop) { if ([destination objectForKey:sourceKey] && [sourceValue isKindOfClass:[NSDictionary class]]) { [[destination objectForKey:sourceKey] mergeWith:(NSDictionary *)sourceValue]; } else { [destination setObject:sourceValue forKey:sourceKey]; } }]; } else { [destination setObject:value forKey:key]; } }]; [self.delegate metaDataChanged:self]; } } @end