2
votes

Hello everyone I am trying to implement Game Center on my iOS8 app and have run into a crash on the iPad. I already have the achievements and leaderboards set up and can successfully hit the blue share button on the iPhone but when i press share on the iPad the GKGameCenterViewController crashes and gives me the following report:

Application Specific Information: *** Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x7b1480a0>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.' terminating with uncaught exception of type NSException abort() called CoreSimulator 110.4 - Device: iPad Retina - Runtime: iOS 8.1 (12B411) - DeviceType: iPad Retina

Any help would be appreciated thank you!

2

2 Answers

0
votes

I got the same crash. When I present the GKGameCenterViewController modally, it's important I provide the sourceView, using the code in this order:

    gameCenterVC.modalPresentationStyle = .Popover
    gameCenterVC.popoverPresentationController?.sourceView = view!
    gameCenterVC.popoverPresentationController?.sourceRect = view!.frame
    presentViewController(gameCenterVC, animated: true, completion: {})

Your error reads

"reason: 'UIPopoverPresentationController [...]"

which suggests your modalPresentationStyle = .Popover.

In that case, you will need to set the source view or button bar, like the rest of the error indicates.

The instance popoverPresentationController in non-nil because...

If you created the view controller but have not yet presented it, accessing this property creates a popover presentation controller when the value in the modalPresentationStyle property is UIModalPresentationPopover

according to popoverPresentationController

0
votes

I am testing on an iPad Air with iOS 9.3.

I am getting it to run without crashing [using my solution in the above post], but it does not display the game center popups or view controllers with

modalPresentationStyle = .Popover

However, I do get my view controllers and sign in pop ups when I set

modalPresentationStyle = .Fullscreen