码迷,mamicode.com
首页 > 移动开发 > 详细

iOS9的那些坑 — — WeiboSDK registerApp启动就崩溃

时间:2016-03-18 19:34:32      阅读:449      评论:0      收藏:0      [点我收藏+]

标签:

 

在升级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

 

iOS9的那些坑 — — WeiboSDK registerApp启动就崩溃

标签:

原文地址:http://www.cnblogs.com/A--G/p/5292919.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!