TWTweetComposeViewController 在 IOS6 中已弃用

Posted

技术标签:

【中文标题】TWTweetComposeViewController 在 IOS6 中已弃用【英文标题】:TWTweetComposeViewController deprecated in IOS6 【发布时间】:2012-09-22 18:42:09 【问题描述】:

我的代码按预期工作,只是我需要删除此警告消息。 ios6 中不推荐使用 TTWeetComposeViewController。 ios6 中这个内置的视图控制器有什么替代品吗?

这是我的示例代码。

if ([TWTweetComposeViewController canSendTweet]) 
    // Initialize Tweet Compose View Controller
    TWTweetComposeViewController *vc = [[TWTweetComposeViewController alloc] init];
    // Settin The Initial Text
    [vc setInitialText:@"This tweet was sent using the new Twitter framework available in iOS 5."];
    // Adding an Image
    UIImage *image = [UIImage imageNamed:@"sample.jpg"];
    [vc addImage:image];
    // Adding a URL
    NSURL *url = [NSURL URLWithString:@"http://mobile.tutsplus.com"];
    [vc addURL:url];
    // Setting a Completing Handler
    [vc setCompletionHandler:^(TWTweetComposeViewControllerResult result) 
        [self dismissModalViewControllerAnimated:YES];
    ];
    // Display Tweet Compose View Controller Modally
    [self presentViewController:vc animated:YES completion:nil];
 else 
    // Show Alert View When The Application Cannot Send Tweets
    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];

【问题讨论】:

你在哪里看到的 TTWeetComposeViewController ? developer.apple.com/library/ios/#documentation/Twitter/… 【参考方案1】:

是的,您应该在 iOS 6 上使用 Social Framework。这要归功于 iOS 上现在提供的 Facebook 集成。您将能够从那里使用 Twitter 和 Facebook。

【讨论】:

【参考方案2】:

在 iOS 5 和 iOS 6 之间使用社交网络有一些变化。 1. 关于库:在 iOS 6 中我们使用 Social framework 而不是 Twitter 框架。 2. 我们使用 SLComposeViewController 代替 TWTweetComposeViewController。 3.请将一些api与以下代码进行比较:

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) 

        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

        SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result)
            if (result == SLComposeViewControllerResultCancelled) 

                NSLog(@"Cancelled");

             else

            
                NSLog(@"Done");
            

            [controller dismissViewControllerAnimated:YES completion:Nil];
        ;
        controller.completionHandler =myBlock;

        //Adding the Text to the facebook post value from iOS
        [controller setInitialText:@"Test Post from mobile.safilsunny.com"];

        //Adding the URL to the facebook post value from iOS

        [controller addURL:[NSURL URLWithString:@"http://www.mobile.safilsunny.com"]];

        //Adding the Image to the facebook post value from iOS

        [controller addImage:[UIImage imageNamed:@"fb.png"]];

        [self presentViewController:controller animated:YES completion:Nil];

    
    else
        NSLog(@"UnAvailable");
    

只有一点点不同,但它们更棒。

偏好: - safilsunny 提示:http://www.mobile.safilsunny.com/integrating-facebook-ios-6/

谢谢,

【讨论】:

以上是关于TWTweetComposeViewController 在 IOS6 中已弃用的主要内容,如果未能解决你的问题,请参考以下文章