0

由于 ios5.0 中添加了 twitter 框架,我正在使用它的类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];
    }

在此步骤中,我需要向用户显示 twitter 的登录页面。为此,我是否应该将用户重定向到设置以登录用户?

如果是,则此代码不起作用

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

我也读过一些这在 ios6 中不起作用的地方。那么我应该怎么做才能让用户登录一会儿而不直接发送推文。现在我只想让用户登录。

我也参考了这个问题 它与 ios6 一起工作得很好,但在这种情况下,我该如何处理 ios5.1 ?

任何帮助将不胜感激....

4

1 回答 1

2

我用下面的条件编码想通了。我只有这种方式。如果有人有任何其他方法,请建议我。

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];
        }];
    }

如果 iOS 是 5.0,那么它将重定向到 Twitter 的登录,否则它将向用户显示警报以转到设置并进行登录。对于 iOS 6.0 及更高版本SLComposeViewController运行良好。

于 2013-03-15T04:11:16.443 回答