Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter log-in - Completed sign-in but not being redirected to my app

as the title describes, it stuck on that state. i didnt find a solution searching the net. no error exist... working with ios swift

image (Hebrew) attached: it basically says : "redirecting you back to the app, it might take a few moments.."

'Youre being redirected' page

Code: 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 completion callback is nit being called.. (its not redirecting back to my app)

@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)
        }
    }
}

Secondary: as further to what i have asked i would also want to change the name of the app bieng presented on permission page, how to do it?

Permission page :

enter image description here

like image 535
Itay Cohen Avatar asked Dec 05 '25 06:12

Itay Cohen


2 Answers

ANSWER: there is more updated method at the delegate, twitter was calling the deprecated method (as you can see above) but i didnt actually handled twitter inside - so no everything is under the updated method and works just fine and organized:

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
}
like image 183
Itay Cohen Avatar answered Dec 07 '25 22:12

Itay Cohen


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)
        }
    }`
like image 41
Mirant Avatar answered Dec 07 '25 22:12

Mirant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!