iOS 13:Twitter登录未重定向回应用程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS 13:Twitter登录未重定向回应用程序相关的知识,希望对你有一定的参考价值。
Xcode版本:11.2.1,迅捷版:5ios版本:13 *
我已经按照Twitter文档通过适当的回调,URL方案和应用程序委托方法实现了Twitter登录集成。当我在iOS 12.4设备上运行代码时,它运行良好。但是在iOS 13设备上,它不会重定向回应用程序。我想场景代理存在一些问题,但我无法找出确切的问题。
这里是代码
应用程序委托
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
TWTRTwitter.sharedInstance().start(withConsumerKey: "consumer key", consumerSecret: "consumer secret key")
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let directedByFB = ApplicationDelegate.shared.application(app, open: url, options: options)
let directedByTWTR = TWTRTwitter.sharedInstance().application(app, open: url, options: options)
let directedByGGL = GIDSignIn.sharedInstance()?.handle(url) ?? false
return directedByGGL || directedByTWTR || directedByFB
}
回叫网址twitterkit-consumerKey://
URL方案twitterkit-consumerKey
查看控制器代码
TWTRTwitter.sharedInstance().logIn(completion: { (session, error) in
if let twitterSession = session {
let credential = TwitterAuthProvider.credential(withToken: twitterSession.authToken, secret: twitterSession.authTokenSecret)
}
})
答案
在TWTRTwitter登录方法中添加self.dismiss。它帮助了我。
TWTRTwitter.sharedInstance().logIn(with: self) { (session, error) in
if (session != nil) {
print("signed in as (String(describing: session?.userName))");
self.dismiss(animated: true) {
print("Logged in ")
}
let client = TWTRAPIClient.withCurrentUser()
client.requestEmail { email, error in
var emailStr = ""
if (email != nil) {
emailStr = email!
} else {
print("error: (error!.localizedDescription)");
}
if let userName = session?.userName {
let client = TWTRAPIClient(userID: session!.userID)
client.loadUser(withID: session!.userID) { (unwrappedTwtrUser, error) in
guard let twtrUser = unwrappedTwtrUser, error == nil else {
print("Twitter : TwTRUser is nil, or error has occured: ")
print("Twitter error: (error!.localizedDescription)")
return
}
let name = twtrUser.name
let imageUrl = twtrUser.profileImageMiniURL
let token = session!.authToken
}
}
}
} else {
print("error: (error?.localizedDescription ?? "")");
}
以上是关于iOS 13:Twitter登录未重定向回应用程序的主要内容,如果未能解决你的问题,请参考以下文章
firebase.auth().signOut() 在单击注销后未重定向回 mainNav
iOS Facebook SDK 3.0 登录未重定向到原始应用程序
flask_login 中的 login_required 装饰器未重定向到上一页
在 Xamarin Forms 项目中使用 AAD 和 Google 的 Azure 身份验证在授权后未重定向回应用程序