CISSO
这是一个集成简化第三方登录的套件,目前支持Facebook、Google、Line、Apple Sign In等登录方式。
第一步
如果您想使用某个第三方登录,请先访问该服务的官网申请相应的注册并获取所需的数据,例如:facebookAppID、googleAppID。
第二步
Podfile中增加CISSO
target 'YOURPROJECT' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for YOURPROJECT
pod 'CISSO'
end
第三步
在info.plist中增加您申请的服务对应的url scheme设置以及LSApplicationQueriesSchemes
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>GoogleSignIn</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.YOUR_APP_REGIST_CODE</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>LineLogin</string>
<key>CFBundleURLSchemes</key>
<array>
<string>line3rdp.YOUR_APP_REGIST_BUNDLE_ID</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>Facebook</string>
<key>CFBundleURLSchemes</key>
<array>
<string>FROM_FB_REGIST</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>lineauth2</string>
<string>line</string>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbapi20160328</string>
<string>fbauth</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
第四步
在AppDelegate中导入CISSO,并在launch func中实现您需要的dataSource,如果不使用第三方服务则不需要实现,并调用config让manager帮您完成相关设置。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
SSOManager.shared().facebookDataSource(dataSource: self)
//SSOManager.shared().lineDataSource(dataSource: self)
SSOManager.shared().setConfig(application: application, launchOptions: launchOptions, dataSource: self)
return true
}
extension AppDelegate: FacebookDataSource{
var facebookAppID: String {
return "YOUR_FACEBOOK_APPID"
}
var facebookDisplayName: String {
return "YOUR_FACEBOOK_DISPLAYNAME"
}
}
第五步
当您需要执行登录操作时调用func并选择合适的登录类型,处理结果即可完成登录操作
SSOManager.shared().loginWithThirdParty(type: .FACEBOOKLOGIN, presentVC: self) { (result) in
switch result{
case .success(let model):
print(model)
case .cancelled:
return
case .failure(let error):
print(error.localizedDescription)
}
}
许可证
MacDown遵循MIT许可证发布。更多详情请参阅许可证。