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 ?? "")");
}