5

我一直在使用此代码发布推特。

SLComposeViewController *fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];


if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
    SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){

        [fbController dismissViewControllerAnimated:YES completion:nil];

        switch(result){
            case SLComposeViewControllerResultCancelled:
            default:
            {
                NSLog(@"Cancelled.....");

            }
                break;
            case SLComposeViewControllerResultDone:
            {
                NSLog(@"Posted....");
                UIAlertView *alertView = [[UIAlertView alloc]
                                          initWithTitle:@"Success"
                                          message:@"Posted Successfully"
                                          delegate:self
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
                [alertView show];

            }
                break;
        }};

    [fbController addImage:[UIImage imageNamed:@"1.jpg"]];
    [fbController setInitialText:@"Check out this article."];
    //[fbController addURL:[NSURL URLWithString:@"http://soulwithmobiletechnology.blogspot.com/"]];
    [fbController setCompletionHandler:completionHandler];
    [self presentViewController:fbController animated:YES completion:nil];
}

如果用户没有设置 twitter 帐户,它会显示具有设置和取消按钮的警报。但它没有在设备中显示警报?任何人都可以帮助我吗?提前致谢 。

4

3 回答 3

5

Facebook 分享也会发生同样的事情。删除测试:

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])

如果用户的 Twitter 帐户尚未在 iOS 6 中设置,则上述测试将评估为 false,并且不会执行任何共享代码。

相反,如果您跳过检查并尝试显示SLComposeViewController,iOS 将提示用户设置他们的 Twitter 帐户。

于 2013-09-01T12:58:51.033 回答
1
BOOL canCompose=  [SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter];

    if (canCompose) {


        SLComposeViewController *fbCompose=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
        [fbCompose setInitialText:addressLabel.text];
        [self presentViewController:fbCompose animated:YES completion:nil];
    }

一次尝试此代码而不是使用 completionHandler

于 2013-07-19T06:42:14.610 回答
0

遵循本教程。在这里打开警报。

http://www.appcoda.com/ios-programming-101-integrate-twitter-and-facebook-sharing-in-ios-6/

- (IBAction)postToTwitter:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
    SLComposeViewController *tweetSheet = [SLComposeViewController
                                           composeViewControllerForServiceType:SLServiceTypeTwitter];
    [tweetSheet setInitialText:@"Great fun to learn iOS programming at appcoda.com!"];
    [self presentViewController:tweetSheet animated:YES completion:nil];
}}
于 2013-07-19T09:05:50.610 回答