14
votes

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.

1
Does [Twitter sharedInstance] return an object? - meaning-matters
@meaning-matters yep, it returns a Twitter object. - Can Poyrazoğlu
Nasty issue. Did you add the twitter URL to your app? - meaning-matters
@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
have you added in your appDelegate Fabric.with([Crashlytics.self(), Twitter.self()]) Twitter.sharedInstance().start(withConsumerKey: "KEY", consumerSecret:"SECRET")? Look through this answer stackoverflow.com/questions/40018848/… - Alexandr Kolesnik

1 Answers

5
votes

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.