ShareSDK在iOS9下注意事项

参考

  1. 参考 iOS9之前的文章
  2. ShareSDK 快速集成
  3. ShareSDK在适配iOS 9系统
  4. 使用 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>NSIncludesSubdomains</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
        }

错误四:QQ 无法分享

这里写图片描述
解决方法:
点击项目->Targets->info->URL Types
即:
这里写图片描述

相关代码:

在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
            }
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值