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

匆匆过客 提交于 2019-12-11 07:38:28

问题


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:


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.



来源:https://stackoverflow.com/questions/48187918/tweeting-using-twitterkit-fails-when-twitter-app-is-not-installed-in-ios-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!