Game Center share achievement or leaderboard crashes on iPad iOS 8 - swift

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!

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

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

Related

Swift app crashes when popToRootViewController called - Exc Bad Access

My Swift app crashes when I have about 4 view controllers on my navigation stack and then at the 4th I call popToRootViewController. It pops, so I know the UINavigationController exists, but the app crashes without any error other than Exc Bad Access. It also crashes when I dismiss the UINavigationController instead of popping to root view controller.
Note: This happens only when running app on my test device. When my it's ran while my test device is connected to Xcode, it never crashes.
This is the only code in my final view controller, other than viewDidLoad of course.
Code:
#IBAction func closeBtnPressed(sender: AnyObject) {
//dismissViewControllerAnimated(true, completion: nil)
self.navigationController?.popToRootViewControllerAnimated(true)
}
Any ideas? Thanks!

iOS - Testing view controllers

I've got a really weird and unexplainable problem and it's like the whole day I'm trying to fix it without any result.
I have setup a testing target for my iOS project, following the doc steps.
I'm using Xcode Version 4.5.2 (4G2008a).
I'm also using kiwi. Every test works fine, apart when it comes to load the view of a view controller with xib.
The view controller is a simple UIViewController with a MKMapView, a button and a searchbar, all properly hooked to the owner's IBOutlets.
In the test I'm writing something like:
__block MapViewController *mapVC = [[MapViewController alloc] initWithNibName:#"MapViewController"
bundle:[NSBundle bundleWithIdentifier:#"com.myorg.MyAppTest"]];
it(#"Loads the view", ^{
[mapVC loadView];
});
While executing the test (on iPhone Simulator 5.0) I get a bunch of these in the console:
ERROR: System image table has not been initialized. Do not ask for
images or set up UI before UIApplicationMain() has been called.
After that I almost always get this error
[__NSCFType pointSize]: unrecognized selector sent to instance
0x19cb970
On iPhone 6 Simulator I get initially this error
Unknown Device Type. Using UIUserInterfaceIdiomPhone based on screen
size
Followed by this
-[__NSCFType screenFontWithRenderingMode:]: unrecognized selector sent to instance 0xeba1540
I hope someone can help me, this thing is driving me mad.

UIPopoverController and UISplitView in iOS 5.1 -> unknown function: _presentPopoverBySlidingIn:

I canĀ“t find nothing about:
UIPopoverController _presentPopoverBySlidingIn:fromEdge:ofView:animated:stateOnly:notifyDelegate:
I got following error message:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController _presentPopoverBySlidingIn:fromEdge:ofView:animated:stateOnly:notifyDelegate:]: Popovers cannot be presented from a view which does not have a window.'
I start my iPad-App in Portrait-Mode. And because I need some steps to be done from the master-VC, I present the Popover-Controller programmatically via
[ _masterPopoverController presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
When I want to dismiss the Popover manually (via touch or swipe outside the popover), the above error occurs.
The problem exists since iOS 5.1.

performSelector throws UIViewControllerHierarchyInconsistency exception

I was developing my application on XCode 4.1, for iOs 4.3, but yesterday I've updated it to XCode 4.2 with iOs 5.0 SDK.
When I run my application in iphone 4.3 simulator, it works great.
I decided to test it on iphone 5.0 simulator, and following problems appeared:
I've got a view controller f.e "MyViewController", and a custom class which implements some custom component "MyCustomComponent" which is added to "MyViewController". There is a button in MyCustomComponent, and when its touched it peformSelector from MyViewController, and it leads to crash with EXC_BAD something. Same code works on iPhone 4.3 simulator just perfectly. Any ideas?
Custom navigation bar - doesn't work at all. I'm trying to set custom background implementing UINavigationBar, and overriding drawRect, but it doesn't shows in ios 5.
OK, so i guess I figrued it out. My console was off, when i reinstalled xcode, so didn't see any error messages. Turned it on now, and got an error
Terminating app due to uncaught exception
'UIViewControllerHierarchyInconsistency'
Problem was that I was adding MyCustomComponent to MyViewController using
self.view=myCustomComponent.view
when I should be doing
[self.view addSubview:myCustomCoponent.view]
it wasn't an issue in ios 4.3, but seems its a big deal in ios 5.
I struggled with the same problem.
When you create a new Master-Detail Application(without story board), you can see this codes below from AppDelegate.m.
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
"BE NOT DEPENDENT ON MainWindow"
Just start from your own ViewController and set it to delegate.
And don't forget to unlink view from MainWindow.xib else the view will called 2 times.
EXC_BAD_ACCESS implies that the object doesn't exist. Try NSLog-ging the object on which you are performing the performSelector-method.
EDIT: If it crashes when you try logging it, it has been dealloced. Check if you retain the object correctly!
If it is a valid object, try:
if(![obj respondsToSelector:#selector(mySelector:)]){NSLog(#"no such method!");}

UISplitViewController with NavigationControllers (including sample code)

The easiest way to see this problem will be to run the sample project here:
http://drop.io/stackproblem
Basically, It's a uisplitviewcontroller which can be switched between 2 detail views, both of which are navigation controllers.
The problem is that it crashes with the following error:
MultipleDetailViews[8531:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Popovers cannot be presented from a view which does not have a window.'
It crashes with this error if you use the app in PORTRAIT and you navigate (still in portrait) from the first controller, to the second, to the first, to the second, and then boom CRASH using the popover controller.
One way to stop the crash is to stop lazy loading the navigation controllers and to load them fresh everytime but this isn't an option for the app I'm making.
Any ideas and I may fall in love.
Try using if (self.view.window != nil) just before the line that's causing the crash.