TWTweetComposeViewController警报未找到Twitter帐户

时间:2013-09-24 13:11:44

标签: twitter ios7

在ios7中,我可以显示No Twitter Accounts Alert,但它在ios7以下版本中完美运行

以下是我的源代码。

TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init];
//hide the tweet screen
viewController.view.hidden = YES;
//    viewController.view.backgroundColor=[UIColor clearColor];
//    viewController.view.opaque=NO;
//fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1
viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
    if (result == TWTweetComposeViewControllerResultCancelled) {
        [self dismissModalViewControllerAnimated:NO];
    }
};
[self presentModalViewController:viewController animated:NO];

//hide the keyboard
[viewController.view endEditing:YES];

1 个答案:

答案 0 :(得分:5)

在iOS 6.0中不推荐使用

TWTweetComposeViewController,您需要使用SLComposeViewController,具体如下:

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
    SLComposeViewController *sheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

    SLComposeViewControllerCompletionHandler completionBlock = ^(SLComposeViewControllerResult result){
        if (result == SLComposeViewControllerResultCancelled) {
            NSLog(@"Cancelled");
        } else {
            NSLog(@"Done");
        }

        [sheet dismissViewControllerAnimated:YES completion:Nil];
    };
    sheet.completionHandler = completionBlock;

    //Adding the Text to the post value from iOS
    [sheet setInitialText:@"hello twitter"];
    [self presentViewController:sheet animated:YES completion:Nil]; 
}