Popover crashing on iPad (SpriteKit game)

By | March 25, 2018

Recently I discovered that it’s necessary to use Popover to display the ActivityViewController on iPad. I found this website as a main reference:

How to share things with a UIActivityViewController

It’s perfectly explained, but I can’t make it work from my SpriteKit game. I double-checked with other examples and all seems to be in its place… but this crash on iPad anyways, without any meaningful message (on iPhone it works). I have no idea on what’s wrong. If somebody experienced the same, any clue will be very welcomed!

UIActivityViewController *activityController = [[UIActivityViewController alloc]initWithActivityItems:@[twitterText] applicationActivities:nil];

UIViewController* viewController = self.view.window.rootViewController;

activityController.modalPresentationStyle = UIModalPresentationPopover;

[viewController presentViewController:activityController animated:YES completion:nil];

UIPopoverPresentationController *popController = [activityController popoverPresentationController];
popController.permittedArrowDirections = UIPopoverArrowDirectionDown;
popController.sourceRect = CGRectMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame),200,200);