大佬教程收集整理的这篇文章主要介绍了swift利用友盟实现新浪微博SSO授权登录,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
添加新应用
,填写完应用基本信息后,将进入"下载SDK并添加代码"页面,此页面即可得到Appkey。最新版SDK下载地址:http://dev.umeng.com/social/ios/sdk-download
将UMSocial_Sdk_x.x.x
的文件夹以及UMSocial_Sdk_Extra_Frameworks
目录下的SinaSSO
文件夹拖入工程目录:
具体如何桥接这里就不说明了,我们需要在桥接文件中包含以下两个头文件
#import "UMSocial.h"
"UMSocialSinaSSOHandler.h"
在AppDelegate内设置友盟AppKey
func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// 设置Appkey
UMSocialData.setAppKey("5608de9de0f55afaae0018e6")
return true
}
let snsPlatform: UMSocialSnsPlatform = UMSocialSnsPlatformManager.getSocialPlatformWithName(UMShareToSina)
snsPlatform.loginClickHandler(self,UMSocialControllerservice.defaultControllerservice(),true,{response in
if response.responseCode == UMSResponseCodesuccess {
let snsAccount:UMSocialAccountEntity = UMSocialAccountManager.socialAccountDictionary()[UMShareToSina] as! UMSocialAccountEntity
print("username is \(snsAccount.userName),uid is \(snsAccount.usid),token is \(snsAccount.accessToken) url is \(snsAccount.iconURL)")
}
})
//获取accestoken以及新浪用户信息,得到的数据在回调Block对象形参respone的data属性
UMSocialDataservice.defaultDataservice().requestSnsInformation(UMShareToSina) { (responsE) -> Void in
print(response.data)
}
使用SSO授权方式,在用户安装了微博客户端并登录时,可以在分享过程中不需要输入账号密码,直接通过微博客户端授权,随后进行网页分享,免去了用户输入密码的过程。 在用户未安装客户端时,则自动跳转到网页授权方式,微博SSO授权友盟提供了微博原生SDK与非原生SDK两种方式,本文介绍的是微博原生SDK。
在xcode中打开工程配置文件,选择“Linked Frameworks and Libraries”一栏,点击“+”图标添加下列库文件:@H_404_30@ 在other linker flags增加-ObjC 选项,并添加ImageIO.framework@H_404_30@ Security.framework@H_404_30@ libiconv.dylib@H_404_30@ SystemConfiguration.framework@H_404_30@ CoreGraphics.Framework@H_404_30@ libsqlite3.dylib@H_404_30@ CoreTelephony.framework@H_404_30@ libstdc++.dylib@H_404_30@ libz.dylib
在你的工程设置项,targets 一栏下,选中自己的 target,在 Info->URL Types 中添加 URL scheR_169_11845@es,格式为“wb”+新浪appkey,例如“wb126663232”
Bool {
//打开新浪微博的SSO开关,设置新浪微博回调地址,这里必须要和你在新浪微博后台设置的回调地址一致。若在新浪后台设置我们的回调地址,“http://sns.whalecloud.com/sina2/callBACk”,这里可以传nil
UMSocialSinaSSOHandler.openNewSinaSSOWithAppKey("2923156246",redirectURL: "http://sns.whalecloud.com/sina2/callBACk")
return true
}
LeopenURL url: NSURL) -> Bool {
return UMSocialSnsservice.handLeopenURL(url)
}
:rgb(133,openURL url: NSURL,sourceApplication: String?,Annotation: AnyObject) -> UMSocialSnsservice.handLeopenURL(url)
}}
iOS9网络传输适配@H_404_30@ 在info.plist的NSAppTransportSecurity下新增NSAllowsArbitraryLoads并设置为YES,指定所有http连接都可正常请求
<key>NSAppTransportSecurity</key>
<Dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</Dict>
应用跳转白名单@H_404_30@ 如果你的应用使用了如SSO授权登录或跳转分享功能,在iOS9下就需要增加一个可跳转的白名单,指定对应跳转App的URL scheR_169_11845@e,否则将在第三方平台判断是否跳转时用到的canOpenURL时返回NO,进而只进行webview授权或授权/分享失败。@H_404_30@ 同样在info.plist的LSApplicationQueriesscheR_169_11845@es下增加:
key>LSApplicationQueriesscheR_169_11845@es</array>
<!-- 新浪微博 URL scheR_169_11845@e 白名单-->
<String>sinaweibohd</String>
<String>sinaweibo</String>sinaweibosso</String>weibosdk</String>weibosdk2.5</String>
</array>
ld: ‘/Users/**/Framework/SDKs/PolymerPay/Library/mobStat/lib**SDK.a(**ForSDK.o)’ does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setTing ENABLE_BITCODE),obtain an updated library from the vendor,or disable bitcode for this target. for architecture arm64
可以在Build SetTings中将Enable Bitcode设置为No
最后附上示例Demo的github地址:https://github.com/laichunhui/UMSocialLogin_Sina
以上是大佬教程为你收集整理的swift利用友盟实现新浪微博SSO授权登录全部内容,希望文章能够帮你解决swift利用友盟实现新浪微博SSO授权登录所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。