Twitter 登录 - 已完成登录但未重定向到我的应用

Posted

技术标签:

【中文标题】Twitter 登录 - 已完成登录但未重定向到我的应用【英文标题】:Twitter log-in - Completed sign-in but not being redirected to my app 【发布时间】:2017-02-04 10:39:03 【问题描述】:

正如标题所描述的,它停留在那个状态。 我没有找到搜索网络的解决方案。 不存在错误... 使用 ios swift

图片(希伯来语)附: 它基本上说:“将您重定向回应用程序,可能需要一些时间......”

代码: AppDelegate -

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool 

    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

    var configureError: NSError?
    GGLContext.sharedInstance().configureWithError(&configureError)
    assert(configureError == nil, "Error configuring Google services: \(configureError)")

    Fabric.with([Twitter.self])

    return true



//deprecaed - for support
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool 
    let directedByFB = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
    let directedByGoogle = GIDSignIn.sharedInstance().handle(url as URL!, sourceApplication: sourceApplication,annotation: annotation)
    return directedByFB || directedByGoogle



func application(application:UIApplication, openURL url: URL, options: [String: AnyObject]) -> Bool 
    if Twitter.sharedInstance().application(application, open: url, options: options) 
        return true
    
    return GIDSignIn.sharedInstance().handle(url as URL!, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication.rawValue] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation.rawValue])

SocialChooserViewController - TWTRAPIClient 完成回调没有被调用..(它没有重定向回我的应用程序)

@IBAction func continueLoginWithTwitter() 
    Twitter.sharedInstance().logIn(withMethods: [.webBased])  session, error in
        guard session != nil else 
            print("error connecting with Twitter: \(error?.localizedDescription)");
            return
        
        self.chosenMedia = .twtr
        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
            
            _ = self.user.set(firstAndFamilyName: twtrUser.name)
            self.user.set(imageURL: twtrUser.profileImageMiniURL)
            self.user.set(token: session!.authToken)
            self.performSegue(withIdentifier: "toProfileVC", sender: self)
        
    

中学: 至于我所问的,我还想更改权限页面上显示的应用程序 bieng 的名称,该怎么做?

权限页面:

【问题讨论】:

插入代码 =] 方法成功后是否调用application(application:UIApplication, openURL url 【参考方案1】:

回答: 委托有更多更新的方法, twitter 正在调用已弃用的方法(如您在上面看到的),但我实际上并没有在内部处理 twitter - 所以没有一切都在更新的方法下并且工作得很好并且有条理:

func application(_ application:UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any]) -> Bool 
    print("called")
    let directedByFB = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, options: options)
    let directedByTWTR =  Twitter.sharedInstance().application(application, open: url, options: options)
    let directedByGGL =  GIDSignIn.sharedInstance().handle(url as URL!, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
    return directedByGGL || directedByTWTR || directedByFB

【讨论】:

【参考方案2】:
From ios13 we have scenedelegate file so for that with appdelegate openURL method we also need to manage the method in scenedelegate file via the below delegate method for twitter.  

`func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) 
        if let openURLContext = URLContexts.first
          let url = openURLContext.url
          let options: [AnyHashable : Any] = [
            UIApplication.OpenURLOptionsKey.annotation : openURLContext.options.annotation as Any,
            UIApplication.OpenURLOptionsKey.sourceApplication : openURLContext.options.sourceApplication as Any,
            UIApplication.OpenURLOptionsKey.openInPlace : openURLContext.options.openInPlace
          ]
          TWTRTwitter.sharedInstance().application(UIApplication.shared, open: url, options: options)
        
    `

【讨论】:

【参考方案3】:

Swift 4.1 - Xcode 9.3 的选择答案

播客文件

pod 'FacebookLogin'
pod 'TwitterKit'
pod 'GoogleSignIn'

AppDelegate

import FacebookCore
import TwitterKit
import GoogleSignIn

...

func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any]) -> Bool 
   let directedByFB = SDKApplicationDelegate.shared.application(application, open: url, options: options)
   let directedByTWTR =  TWTRTwitter.sharedInstance().application(application, open: url, options: options)
   let directedByGGL =  GIDSignIn.sharedInstance()
     .handle(url,
          sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
          annotation: options[UIApplicationOpenURLOptionsKey.annotation]
   )
   return directedByFB || directedByTWTR || directedByGGL


...

【讨论】:

【参考方案4】:

iOS 14 中 Xcode 12 中的另一种解决方案。

实际上我的登录按钮的类是 TWTRLogInButton。 所以我将它替换为 UIButton 类型。然后我很快被重定向到我的应用程序。

例如:- 替换

@IBOutlet weak var twitterLoginButton: TWTRLogInButton!

@IBOutlet weak var twitterLoginButton: UIButton!

【讨论】:

以上是关于Twitter 登录 - 已完成登录但未重定向到我的应用的主要内容,如果未能解决你的问题,请参考以下文章

成功登录后登录页面未重定向到主页

Grails Spring Security登录失败未重定向到登录视图

使用 facebook 登录网站后重定向页面

使用谷歌登录后,登录按钮未重定向到主页

Twitter API登录无法无缝重定向已批准的用户

登录页面未重定向到另一页面