您的位置:首页 > 移动开发 > IOS开发

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
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: