twitter-archive / twitter-kit-ios

Twitter Kit is a native SDK to include Twitter content inside mobile apps.
Apache License 2.0
690 stars 449 forks source link

In application not presenting Safari if twitter app is not install #74

Closed Nidhi30 closed 6 years ago

Nidhi30 commented 6 years ago

I am trying to login with Twitter, but if twitter is not installed it is not allowing me to login via safari, It is giving this kind if warning Warning: Attempt to present <UINavigationController: 0x10787d000> on <UINavigationController: 0x1080b0e00> whose view is not in the window hierarchy! here is my code

in appdelegate

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { TWTRTwitter.sharedInstance().start(withConsumerKey: "Consumarkey", consumerSecret: "Secret") }

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

    if  GIDSignIn.sharedInstance().handle(url,sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,annotation: options[UIApplicationOpenURLOptionsKey.annotation])
    {
        return true
    }
    if TWTRTwitter.sharedInstance().application(app, open: url, options: options) {
        return true
    }
    return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: [:])

}

TWTRTwitter.sharedInstance().logIn(completion: { (session, error) in if (session != nil) { let user_id = session?.userID self.type = social.twitter.rawValue DELEGATE.dicSocialSignUpData.setValue(String(user_id!), forKey: "socialId") self.socialid = user_id! let client = TWTRAPIClient.withCurrentUser() client.loadUser(withID: userid!, completion: { (user, error) in if user != nil { let name = user!.name if name.contains("") { let seprated_name = name.components(separatedBy: " ") self.firstname = seprated_name[0] self.lastname = seprated_name[1] } else { self.firstname = name } DELEGATE.dicSocialSignUpData.setValue(user!.name, forKey: "name") DELEGATE.dicSocialSignUpData.setValue(user!.profileImageURL, forKey: "profile_image") self.image = user!.profileImageURL } client.requestEmail { email, error in if (email != nil) { self.emailR = "(String(describing: email!))" DELEGATE.dicSocialSignUpData.setValue(String(describing: email!), forKey: "email") } else { print("error: (String(describing: error?.localizedDescription))"); } let store = TWTRTwitter.sharedInstance().sessionStore if let userID = store.session()?.userID { store.logOutUserID(userID) } self.socialLogin(social_id: "(String(describing: session?.userName))", social_type: social.twitter.rawValue) } })

        } else {
            print("error: \(String(describing: error?.localizedDescription))");
        }
    })

Also seted callback url twitterkit-ConsumerKey://

pods I used TwitterCore (3.1.0) TwitterKit (3.3.0)

thint1285 commented 6 years ago

I have a problem too.

rajul-arora commented 6 years ago

We have a fix that grabs the top view controller in the view controller stack when you call [TWTRTwitter loginWithCompletion:], which should fix the issue you're having here. You can use the method [TWTRTwitter loginWithViewController:withCompletion] and specify the view controller we should present safari on top of, which will also fix the issue you are dealing with here. Hope that helps!

alpamys-qanybet commented 6 years ago

@rajul-arora, hi there, give us example please by code how to implement it.

alpamys-qanybet commented 6 years ago

@rajul-arora, in my case, the following error occurs Error: Request failed: forbidden (403)

taichi-jp commented 6 years ago

I encountered this issue. I think this is related to that Callback Urls get required from June. https://developer.twitter.com/en/docs/basics/callback_url.html How to fix this?

SSHuiqin commented 6 years ago

Having same issue as what @alpamys-qanybet had. Tried both [TWTRTwitter loginWithCompletion:] and [TWTRTwitter loginWithViewController:withCompletion] mentioned by @rajul-arora on the post above. Both failed with error : Error: Request failed: forbidden (403)

taichi-jp commented 6 years ago

Fixed by https://stackoverflow.com/questions/50571047/callback-url-not-approved-despite-being-provided-twitter-api/50850233#50850233 !!

alpamys-qanybet commented 6 years ago

@taichi-jp, @SSHuiqin , @rajul-arora , @Nidhi30 , @oNguyenTamThi , never mind, problem was with callback url in twitter dev console. it must be: twitterkit-CONSUMER_KEY:// for iOS twittersdk:// for Android

s1lence2012 commented 5 years ago

if I hasn't installed the twitter app, it will open the web auth page.It seems ok.

If I install the twitter app, it will open the twitter app to auth, but when I cancel return to my app, it open the twitter web page authorization. Why? Now repeatedly evoke, how can I only evoke an authorization once? @alpamys-qanybet @rajul-arora

m3rkus commented 5 years ago

I have the same issue, web view appears on cancel or authorize button in twitter app (only when twitter app is installed). Any solutions on this?