The following code works fine on an iPhone on iOS 13.5.1 and an iPad on iOS 12.4.7, but nothing happens when it's triggered on an iPad on iOS 13.5.1:
- (void)notificationFired:(NSNotification *)notification {
if (notification != (id)[NSNull null] && [[notification name] isEqualToString:@"OpenActionSheet"]) {
NSString *path = [notification userInfo][@"path"];
printf("Received path: %s", path.UTF8String);
NSURL *url = [NSURL fileURLWithPath:path];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:nil];
[controller setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
printf("%s", "Share sheet closed");
UnitySendMessage("ShareListener", "Complete", path.UTF8String);
}];
if (IDIOM == IPAD)
controller.modalPresentationStyle = UIModalPresentationPopover
[self.window.rootViewController presentViewController:controller animated:YES completion:nil];
if (IDIOM == IPAD) {
UIPopoverPresentationController *popover = controller.popoverPresentationController;
popover.sourceView = self.window.rootViewController.view;
}
}
}
I've also tried
if ([controller respondsToSelector:@selector(popoverPresentationController)])
controller.popoverPresentationController.sourceView = self.rootView;
[self.window.rootViewController presentViewController:controller animated:YES completion:nil];
instead of the IDIOM == IPAD
blocks, but that has the same results. What am I missing?
Instead of just assigning sourceView
, you should also assigning sourceRect
Like
popover.sourceRect = CGRectMake(0, 0, 100, 100) // change the rect to the frame you want the view to appear
I hope it'll fix your problem. Tested in iPad Pro (12.9-inch) (4th generation) XCode 11.5.