如何在iOS7中为SLComposeViewController添加url?

时间:2013-10-17 11:53:16

标签: ios objective-c ios7 slcomposeviewcontroller

在我的应用中,我使用SLComposeViewController发送推文。我也正在调用它的方法addURL:

[tweetSheet addURL:[NSURL URLWithString:@"http://itunes.com/apps/MyAppName"]];

并且它在iOS 6中运行良好,但在iOS 7中,它在屏幕上显示后立即打开iTunesStore。我该如何解决?

更新:

 if ([SLComposeViewController isAvailableForServiceType:network])
{
    AppController *appController = (AppController *)[[UIApplication sharedApplication] delegate];
    MyNavigationController *navController = appController.navController;

    UIViewController *currentController = [[navController viewControllers] lastObject];

    SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:network];
    [tweetSheet setInitialText:text];
    [tweetSheet addImage:[UIImage imageNamed:temp_character]];
    [tweetSheet addURL:[NSURL URLWithString:@"http://itunes.com/apps/MyAppName"]];

    tweetSheet.completionHandler = ^(SLComposeViewControllerResult result){

        [currentController dismissViewControllerAnimated:YES completion:nil];

        if (result == SLComposeViewControllerResultDone)
          [[NSNotificationCenter defaultCenter] postNotificationName:HC_TWEET_SENT_NOTIFICATION object:nil];

    };

    [currentController presentViewController:tweetSheet animated:YES completion:nil];
}

1 个答案:

答案 0 :(得分:0)

您的自定义socialIntegration类中有一个错误。如果Facebook在设备上可用,它只返回SLComposeViewController。如果不是,则不返回任何内容。

但是,实际调用它时不会对此进行测试:

SLComposeViewController * faceSheet=[self.socialIntegration showFacebook:@"text" andImage:nil andLink:@"link" andView:self];
        dispatch_sync(dispatch_get_main_queue(), ^{
            //[self netConnectionTrue:cell Connected:answer];
            //[tempAlertView show];
            [self presentViewController:faceSheet animated:YES completion:NO];

        });

...你没有检查faceSheet是否为零。因此,如果没有Facebook帐户,您可以使用nil对象调用presentViewController,这会触发您看到的错误。

您在iOS 7上看到此问题的原因是您的链接FB帐户可能已重置,但它可能也是iOS 6上用户崩溃的原因。