1

在 ios7 中,我可能会显示无 Twitter 帐户警报,但它在 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];
4

1 回答 1

5

TWTweetComposeViewController在 iOS 6.0 中已弃用,您需要使用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]; 
}
于 2013-10-14T22:05:32.807 回答