在升級Xcode7.2.1后,在App加載時直接崩掉,仔細看了,發現是在在注冊微博SDK的時候報錯:
[WeiboSDK registerApp:WBAPPKey];

查了很多資料,最后在github的微博SDk issue討論區中發現有人已經解決了。
解決方法:
在注冊 微博 sdk 之前
1 [NSDictionary aspect_hookSelector:NSSelectorFromString(@"weibosdk_WBSDKJSONString") 2 withOptions:AspectPositionInstead 3 usingBlock:^(id<AspectInfo> info) 4 { 5 return [(NSDictionary*)[info instance] tt_jsonString]; 6 } 7 error:nil];
tt_jsonString 是自一個字典轉字符串的 category;
aspect 可以 pod 安裝;
有人解釋說,猜測weibosdk使用了舊版本的jsonkit.導致了json的解析兼容性出了問題直接升級微博SDK也可以。
這里提供一個字典轉字符串的方法吧:
1 /** 字典轉字符串 */ 2 3 - (NSString*)dictionaryToJson:(NSDictionary *)dic{ 4 5 NSError *parseError = nil; 6 7 NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 8 9 }
Aspects的github鏈接:https://github.com/steipete/Aspects
參考鏈接: https://github.com/sinaweibosdk/weibo_ios_sdk/issues/133
