ShareSDK在iOS9下注意事项
2016-04-12 18:04
459 查看
参考
参考 iOS9之前的文章ShareSDK 快速集成
ShareSDK在适配iOS 9系统
使用 Swift 调用 ShareSDK
分享时出现几个错误
错误一
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file.~参考 3. ShareSDK在适配iOS 9系统这是因为在iOS9下,系统默认会拦截对http协议接口的访问,因此无法获取http协议接口的数据。对ShareSDK来说,具体表现可能是,无法授权、分享、获取用户信息等。
在Info.plist 文件中添加如图:
错误二
-canOpenURL: failed for URL: “weixin://app/wx4e7847f749633a5d/” - error: “This app is not allowed to query for scheme weixin”“分享失败,错误描述:Error Domain=ShareSDKErrorDomain Code=208 \”(null)\” UserInfo={error_message=分享平台[微信]尚未安装客户端!无法进行分享!}”
在Info.plist中设置白名单 ,添加 NSAllowsArbitraryLoads 的字典,然后在其底下
1.添加key 为 Allow Arbitrary Loads 值为YES
2.添加key 为 Exception Domains 字典 在该字典下添加http的网址并设置他的属性,每一个网址有下面三个Key:NSExceptionAllowsInsecureHTTPLoads:YES
NSIncludesSubdomains :YES
NSExceptionRequiresForwardSecrecy:NO
参考3. ShareSDK在适配iOS 9系统
即
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>NSAllowsArbitraryLoads</key> <true/> <key>NSExceptionDomains</key> <dict> <key>shinho.com.cn</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSExceptionAllowsInsecureHTTPLoads - 2</key> <true/> <key>NSExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>eccp.shinho.net.cn</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSExceptionAllowsInsecureHTTPLoads - 2</key> <true/> <key>NSExceptionRequiresForwardSecrecy</key> <false/> </dict> </dict> </dict> </plist>
错误三
fatal error: unexpectedly found nil while unwrapping an Optional value点击分享时,要先判断是否安装微信,在进行内容分享。
if WXApi.isWXAppInstalled() == false{ debugPrint("微信还未安装"); let alert = UIAlertView(title: "温馨提示", message: "您还没有安装微信,请安装后再分享!", delegate: nil, cancelButtonTitle: "我知道了") alert.show() return }
相关代码:
在Appdelegate中加入代码ShareSDK.registerApp(ShareSDKKeys.AppKey, activePlatforms: [SSDKPlatformType.SubTypeWechatSession.rawValue,SSDKPlatformType.SubTypeWechatTimeline.rawValue], onImport: {(platform : SSDKPlatformType) -> Void in switch platform{ case SSDKPlatformType.TypeWechat: ShareSDKConnector.connectWeChat(WXApi.classForCoder()) default: break } }, onConfiguration: {(platform : SSDKPlatformType,appInfo : NSMutableDictionary!) -> Void in switch platform { case SSDKPlatformType.TypeWechat,SSDKPlatformType.SubTypeWechatTimeline: //设置微信应用信息 appInfo.SSDKSetupWeChatByAppId(WeiXinKeys.AppId, appSecret:WeiXinKeys.AppKey) debugPrint("onConfiguration \(platform.rawValue)") break default: break } })
在要分享的时候,代码如下(现在是微信好友和朋友圈分享):
let shareParams = NSMutableDictionary() let shareItem : [AnyObject] = [SSDKPlatformType.SubTypeWechatSession.rawValue ,SSDKPlatformType.SubTypeWechatTimeline.rawValue] shareParams.SSDKSetupShareParamsByText("今日公告的内容。。。。。。。。", images: UIImage(named: "icon108x108.png"), url: NSURL(string: "http://www.shinho.com.cn"), title: "欣和手持", type: SSDKContentType.WebPage) // 显示分享菜单 let sheet : SSUIShareActionSheetController = ShareSDK.showShareActionSheet(UIApplication.sharedApplication().keyWindow, items: shareItem, shareParams: shareParams) { (state:SSDKResponseState, type:SSDKPlatformType, userData:[NSObject : AnyObject]!, content :SSDKContentEntity!,err: NSError!,end: Bool) -> Void in switch state{ case SSDKResponseState.Begin: debugPrint("SSDKResponseState.Begin") break case SSDKResponseState.Success: debugPrint("SSDKResponseState.Success") break case SSDKResponseState.Fail: debugPrint("SSDKResponseState.Fail") break case SSDKResponseState.Cancel: debugPrint("SSDKResponseState.Cancel") break default: break } }
相关文章推荐
- iOS设备唯一标识(可以用版)
- iOS 关于信鸽推送点击推送通知的处理
- iOS 最简单的资料
- iOS 客户端MD5加密方法
- iOS中 imageNamed方法 非常多图片占用大量内存问题
- 应用之间跳转进行传值
- iOS之JSON解析和视频的简单播放
- 纪念一下我的短暂的ios时光
- iOS Core Animation系列之CADisplayLink
- ios-常见的循环引用
- iOS多线程编程之NSOperation
- iOS开发之百度地图大头针的自定义解决方法
- iOS中的initialize与load两个类方法简单理解
- ios开发常用的技巧
- IOS-日期处理
- iOS之轻松上手block(下)
- iOS之轻松上手block(上)
- iOS开发:coredata的简单使用
- IOS atomic与nonatomic,assign,copy与retain的定义和区别
- ios视频保存Error Domain未知错误