我正在尝试从 OpenGL 视图(使用 libGDX/RoboVM)呈现 UIActivityViewController,但结果好坏参半。
它在 iOS 7 和 iOS 8 iPad 上运行良好,但在 iOS 8 iPhone 上它只是暂停应用程序而没有任何事情发生。调试日志中没有什么值得注意的,除了完成块永远不会触发。这是代码:
UIActivityViewController controller = new UIActivityViewController(activityItems, null);
List<String> excludedTypes = new ArrayList<String>();
excludedTypes.add("UIActivityTypePrint");
excludedTypes.add("UIActivityTypeAssignToContact");
excludedTypes.add("UIActivityTypeAddToReadingList");
excludedTypes.add("UIActivityTypeAirDrop");
excludedTypes.add("UIActivityTypeCopyToPasteboard");
controller.setExcludedActivityTypes(excludedTypes);
IOSApplication iosApplication = (IOSApplication)Gdx.app;
// for iPad (https://groups.google.com/forum/#!topic/robovm/fiGDVf6AAsc)
int majorOsVersion = Integer.parseInt(System.getProperty("os.version").substring(0, System.getProperty("os.version").indexOf('.')));
if (majorOsVersion >= 8)
{
UIView sourceView = iosApplication.getUIViewController().getView();
if (width > 0 && height > 0)
{
UIView subView = new UIView(new CGRect(left, top, width, height));
sourceView.addSubview(subView);
sourceView = subView;
}
UIActivityViewControllerExtensions.getPopoverPresentationController(controller).setSourceView(sourceView);
}
iosApplication.getUIViewController().presentViewController(controller, true, null);
我已经验证了该方法是在“主”线程中调用的(希望在 libGDX 上与 CocoaTouch 应用程序中的主线程相同)