¶ QQ login
¶ Preparation
Configure in QQ Internet (opens new window) and Authing Console (opens new window), please refer to QQ Connected iOS App (opens new window).
¶ Integrated QQ login
¶ Step 1: Add Tencent dependency
Enter: https://github.com/Authing/authing-binary in the swift package search bar.
Authing-binary (opens new window) depends on Guard-iOS SDK (opens new window).
Select Up to Next Major Version 1.0.0 for the dependency rule.
Check Tencent after Add Package.
Tencent depends on the version after Guard-iOS 1.4.1 (opens new window).
¶ Step 2: Modify project configuration
Configure the bounce URL of the QQ login component:
- Select the Xcode project, click the plus sign in Targets -> Info -> URL Types.
- Identifier fill in tencentopenapi
- URL Schemes fill in tencent + QQ interconnected APP-ID, for example: tencent102043018.
¶ Step 3: Add a whitelist to start WeChat in Info.plist
Open Info.plist via Source Code, then copy and paste the following code:
<plist version="1.0">
<dict>
...
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tim</string>
<string>mqq</string>
<string>mqqapi</string>
<string>mqqbrowser</string>
<string>mttbrowser</string>
<string>mqqOpensdkSSoLogin</string>
<string>mqqopensdkapiV2</string>
<string>mqqopensdkapiV4</string>
<string>mqzone</string>
<string>mqzoneopensdk</string>
<string>mqzoneopensdkapi</string>
<string>mqzoneopensdkapi19</string>
<string>mqzoneopensdkapiV2</string>
<string>mqqapiwallet</string>
<string>mqqopensdkfriend</string>
<string>mqqopensdkavatar</string>
<string>mqqopensdkminiapp</string>
<string>mqqopensdkdataline</string>
<string>mqqgamebindinggroup</string>
<string>mqqopensdkgrouptribeshare</string>
<string>tencentapi.qq.reqContent</string>
<string>tencentapi.qzone.reqContent</string>
<string>mqqthirdappgroup</string>
<string>mqqopensdklaunchminiapp</string>
<string>mqqopensdkproxylogin</string>
<string>mqqopensdknopasteboard</string>
</array>
...
</dict>
</plist>
¶ Step 4: Set up Associated Domains:
Fill in the host corresponding to the developer's Universal Link.
¶ Step 5: Initialize QQ login
import Guard
import Tencent
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Authing.start(<#AUTHING_APP_ID#>)
Tencent.register(appId: <#your_qq_appkey#>, universalLink: <#your_qq_universalLink#>)}
universalLink Please fill in according to the requirements of QQ Internet.
¶ Step 6: Handle QQ login callback
After Weibo returns to the application, if SceneDelegate is used, the following functions need to be overloaded in SceneDelegate.swift:
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
if let url = userActivity. webpageURL {
_ = Tencent. handleUniversalLink(url: url)
}
}
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
_ = Tencent. handleURL(url: url)
}
If SceneDelegate is not used, it needs to be overloaded in AppDelegate:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let url = userActivity. webpageURL {
return Tencent.handleUniversalLink(url: url)
}
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication. OpenURLOptionsKey : Any] = [:]) -> Bool {
return Tencent. handleURL(url: url)
}
¶ Step 7: Initiate QQ login authorization
¶ QQ authorized login
func login(completion: @escaping Authing.AuthCompletion) -> Void
example
Tencent.login { code, message, userInfo in
if (code == 200) {
// login successful
// userInfo
}
}
If the developer integrates QQ login by himself, after getting the accessToken, he can call the following API in exchange for Authing user information:
¶ Login via QQ authorization code
func loginByTencent(_ accessToken: String, completion: @escaping(Int, String?, UserInfo?) -> Void)
parameter
accessToken
QQ accessToken
example
AuthClient().loginByTencent(accessToken) { code, message, userInfo in
if (code == 200) {
// userInfo: user information
}
}