OStack程序员社区-中国程序员成长平台

标题: ios - UIActivityViewController 在 iPad 上不起作用? iOS 8 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:58
标题: ios - UIActivityViewController 在 iPad 上不起作用? iOS 8

我已遵循类似 SO 问题的建议,但似乎无法完成这项工作。我正在开发一款游戏,它会报告最后的得分,然后是最后得分的分享按钮。

这适用于 iPhone,而我的 iPad 代码如下所示。当我点击分享按钮时,iPad 版本就崩溃了。此代码来自 this tutorial on Coding Explorer .

iPad 代码(不起作用)

- (IBAction)shareButtonid)sender;
{
    NSString * text = [NSString stringWithFormat"I just scored %li in Flying Freddy. Think you can beat it? https://itunes.apple.com/app/id1033007818", (long)_score];

NSArray *objectsToShare = @[text];

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItemsbjectsToShare applicationActivities:nil];

NSArray *excludeActivities = @[UIActivityTypeAirDrop,
                               UIActivityTypePrint,
                               UIActivityTypeAssignToContact,
                               UIActivityTypeSaveToCameraRoll,
                               UIActivityTypeAddToReadingList,
                               UIActivityTypePostToFlickr,
                               UIActivityTypePostToVimeo];

activityVC.excludedActivityTypes = excludeActivities;

[self presentViewController:activityVC animated:YES completion:nil];
}

iPhone 代码(确实有效)

- (IBAction)ShareIt {

    NSString * text = [NSString stringWithFormat"I just scored %li in Flying Freddy. Think you can beat it? https://itunes.apple.com/app/id1033007818", (long)_score];

    NSArray * activityItems = @[text];
    UIActivityViewController * avc = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    avc.excludedActivityTypes = @[ UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];

    [self presentViewController:avc animated:YES completion:nil];    
}



Best Answer-推荐答案


您必须添加源 View 。

尝试添加这一行:

activityVC.popoverPresentationController.sourceView = self.view;

你也可以添加箭头方向:

activityVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionRight;
activityVC.popoverPresentationController.sourceView = sender;

关于ios - UIActivityViewController 在 iPad 上不起作用? iOS 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34404782/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4