Tweeting using Twitterkit fails when Twitter app is not installed in iOS 11

746 Views Asked by At

I am following the documentation of twitter and below is the example code they have given to check logged in user session and tweet using the TWTRComposer.

// Check if current session has users logged in
if ([[Twitter sharedInstance].sessionStore hasLoggedInUsers]) {
    TWTRComposerViewController *composer = [TWTRComposerViewController emptyComposer];
    [fromController presentViewController:composer animated:YES completion:nil];
} else {
    [[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
        if (session) {
            TWTRComposerViewController *composer = [TWTRComposerViewController emptyComposer];
            [fromController presentViewController:composer animated:YES completion:nil];
        } else {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"No Twitter Accounts Available" message:@"You must log in before presenting a composer." preferredStyle:UIAlertControllerStyleAlert];
            [self presentViewController:alert animated:YES completion:nil];
        }
    }];
}

Now, for the case when Twitter app is not installed, the flow goes to the else part given below:

else {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"No Twitter Accounts Available" message:@"You must log in before presenting a composer." preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alert animated:YES completion:nil];
}

Twitterkit should open webview here to ask for twitter login, which is not happening. Anyone have any clue? Any help would be greatly appreciated.

Thanks & Cheers.

1

There are 1 best solutions below

0
On BEST ANSWER

Got it fixed after a lot of trials. And the fix is such a stupid thing:

Go to your app in twitter dashboard: https://apps.twitter.com/ > Go to app settings > Go to Callback URL and fill with any working url. And voila, it will load the webview if the Twitter app is not installed.

Hope it helps someone.