14

I am trying to login to user's Twitter account. I have followed the guide at https://dev.twitter.com/twitterkit/ios/installation to integrate Twitter.

However, when I try to login, nothing happens:

[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession * _Nullable session, NSError * _Nullable error) {
      //not called
       if(session && !error){

       }else{

       }
 }];

I've also tried specifying view controller explicitly:

[[Twitter sharedInstance] logInWithViewController:self completion:^(TWTRSession * _Nullable session, NSError * _Nullable error) {
   //again, not called.
   if(session && !error){

   }else{

   }
}];

Twitter app itself is logged in and perfectly working with my account.

What am I doing wrong?

UPDATE: I've also tried on simulator (which, obviously, doesn't have the Twitter app) in addition to device (which has the Twitter app and a logged in account), it's the same on both scenarios.

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
  • Does `[Twitter sharedInstance]` return an object? – meaning-matters Dec 23 '17 at 14:22
  • @meaning-matters yep, it returns a `Twitter` object. – Can Poyrazoğlu Dec 23 '17 at 15:54
  • Nasty issue. Did you add the twitter URL to your app? – meaning-matters Dec 23 '17 at 17:04
  • @meaning-matters yep. I've followed all the instructions. I have the twitterkit-(myconsumerkey) URL scheme assigned to my app, have my callback URL in twiiter apps dashboard, enabled login and readwrite permissions, have `twitter` and `twitterauth` in `LSApplicationQueriesSchemes`, initialize `Twitter` with my consumer key and secret, but absolutely nothing happens when I call this method. – Can Poyrazoğlu Dec 23 '17 at 23:42
  • have you added in your appDelegate Fabric.with([Crashlytics.self(), Twitter.self()]) Twitter.sharedInstance().start(withConsumerKey: "KEY", consumerSecret:"SECRET")? Look through this answer https://stackoverflow.com/questions/40018848/login-with-twitter-on-ios?rq=1 – Alexandr Kolesnik Dec 29 '17 at 10:07
  • @АлександрКолесник yep. – Can Poyrazoğlu Dec 29 '17 at 12:25

1 Answers1

5

Okay I've figured out the problem. I was mishandling UIApplication openURL:options:completionHandler: method. My app was silently discarding the callback URL request. I've added a case for twitterauth scheme and now it works perfectly.

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
  • Poyrazoglu How you added that? because i am also facing the same issue now. – R. Mohan Nov 11 '18 at 08:00
  • 1
    @R.Mohan go to your target in your project settings, go to Info tab, scroll down, expand URL Types section, click + sign, type `twitterauth` into the "URL Schemes" box (you can leave the other boxes default/empty) – Can Poyrazoğlu Nov 11 '18 at 22:11