1

我有一个基本的 UIActivityViewController 共享一些文本和一个 URL。共享选项是电子邮件、SMS、Twitter 和 Facebook。在 iOS 6 中一切正常,但在 iOS 7 中,当我选择 Twitter 或 Facebook 时,无需触摸任何东西,我的设备会自动关闭我的应用程序,打开 Safari 并转到我尝试共享的 URL。这可能是什么原因造成的?

代码(CustomActivityItemProvider 是基于共享器自定义文本的子类):

if ([UIActivityViewController class]) { // if class exists = ios6+

    // Create array for sharing
    CustomActivityItemProvider *textToShare = [[CustomActivityItemProvider alloc]
                                               initWithStandardText:@"Text to share.\n"];

    NSURL *urlToShare = iTunesShort ? iTunesShort : [NSURL URLWithString:iTunesLink];

    NSArray *activityItems = @[textToShare, urlToShare];

    // Show sharing view
    UIActivityViewController *activityVC = [[UIActivityViewController alloc]
                                            initWithActivityItems:activityItems applicationActivities:nil];
    activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
                                         UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];

    [self presentViewController:activityVC animated:TRUE completion:nil];    
}
4

1 回答 1

0

所以我仍然不知道为什么只有缩短的 URL 会导致这个问题,但解决这个问题的解决方案是urlToSharetextToShare.

// Create array for sharing
NSString *urlToShare = iTunesShort ? iTunesShort : iTunesLink;
NSString *textWithUrl = [NSString stringWithFormat:@"Text to share.\n%@", urlToShare];
CustomActivityItemProvider *textToShare = [[CustomActivityItemProvider alloc]
                                           initWithStandardText:textWithUrl];

NSArray *activityItems = @[textToShare];
于 2013-11-19T16:29:04.430 回答