Question

As twitter framework is added in ios5.0 I am using its class TWTweetComposeViewController

if([TWTweetComposeViewController canSendTweet])
    {
        NSLog(@"can send tweet");
    }
    else{
         NSString *message = @"The application cannot send a tweet at the moment. This is because it cannot reach Twitter or you don't have a Twitter account associated with this device.";
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops" message:message delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [alertView show];
    }

On this step I need to show user the login page of twitter.For that I am confused if i should redirect user to settings to login to user?

And if yes this code is not working

     NSURL *twitterURL = [NSURL URLWithString:@"prefs:root=TWITTER"];
    [[UIApplication sharedApplication] openURL:twitterURL];

Also I have read some where that this will not work in ios6. So what should i do to just make user login for a moment and not send tweet directly. Right now i just want to make user login.

I also refer to this question It is working with ios6 well but in that case how do i handle for ios5.1 ?

Any help will be appreciated....

Was it helpful?

Solution

I figured it out with below conditional coding.. I got only this way. If anyone have any other way please suggest me.

if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
        if(SYSTEM_VERSION_EQUAL_TO(@"5.0"))
        {
            NSURL *twitterURL = [NSURL URLWithString:@"prefs:root=TWITTER"];
            [[UIApplication sharedApplication] openURL:twitterURL];
        }else{
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"No_Tw", nil) message:NSLocalizedString(@"No_TW_Ac", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"Button_Ok", nil) otherButtonTitles:nil, nil];
            [alertView show];
        }
    }

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {
        SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
        tweetSheet.view.hidden=TRUE;

        [self presentViewController:tweetSheet animated:NO completion:^{
            [tweetSheet.view endEditing:YES];
        }];
    }

If iOS is 5.0 then it will redirect to login of Twitter otherwise it will show alert to user to go to settings and do login. And for for iOS 6.0 and larger SLComposeViewController is working fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top