I'm trying to present a UIActivityViewController from an OpenGL view (using libGDX/RoboVM) but am having mixed results.
It works fine on iOS 7 and on iOS 8 iPad, but on iOS 8 iPhone it simply pauses the application without anything happening. Nothing of note in the debug logs, except that the completion block never fires. This is the code:
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);
I have verified that the method is being called in the "main" thread (hopefully on libGDX that's the same main thread as in a CocoaTouch app)
NullPointerException here:
UIActivityViewControllerExtensions.getPopoverPresentationController(controller).setSourceView(sourceView);
getPopoverPresentationController()
returns null on iPhones, which is not a problem in Objective-C land.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.