在没有分享按钮的情况下打开 iOS8 分享菜单

Opening the iOS8 share menu without a share button

我想在我的 unity iOS 游戏中显示一个共享按钮,当用户点击它时,会打开您从标准 cocoatouch 共享按钮获得的共享菜单。到目前为止,我发现的唯一参考资料是,要打开共享菜单,您需要添加一个标准的共享按钮。显然我没有那个选项。

我希望有一些简单的 ObjC 调用,我可以将图像传递给它并让它打开我的统一游戏顶部的共享菜单。

考虑到 opengl 表面和 cocoatouch 的性质,这甚至可能是不可能的。如果是这样的话,我想知道是否有任何简单的方法可以直接分享到 twitter,以及相关文档在哪里。

听起来 UIActivityViewController 是您想要的 class,但是我不太熟悉您如何将其连接到 Unity 以给出完整的答案。

您需要从另一个视图控制器显示 activity 视图控制器。我不确定 Unity 如何包装这些东西,但有可能有一个附加到主 UIWindow(UIWindow 有一个 rootViewController 属性)。如果你能以某种方式得到这些东西,你可能可以从那里展示它。

例如它可能涉及这样的事情:

NSArray *itemsToShare = @[@"Perhaps a high score/brag string here?"];

UIWindow *window = [UIApplication sharedApplication].keyWindow;

UIActivityViewController *share = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];

// warning: these two lines would require iOS 8, but they only govern where the popup points
share.popoverPresentationController.sourceRect = CGRectMake(CGRectGetMidX(window.bounds)-1, CGRectGetMidY(window.bounds)-1, 2, 2);
share.popoverPresentationController.sourceView = window;

[window.rootViewController presentViewController:share animated:YES completion:nil];