I have some odd behaviour in the iOS Simulator with state restoration. I've only recently realized it is only happening in the emulator. I'm wondering if there is something I am doing wrong. But I would also like to share my experience.
I created a single screen project in Xcode 5.0.2. In my application delegate I have only added two methods:
- (BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder
{
NSLog(#"I am restore.");
return YES;
} // */
- (BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder
{
NSLog(#"I am save.");
return YES;
} // */
There are no other changes.
When debugging on an actual iPhone, I get both the log messages; "I am restore" on start up, and "I am save" when I press the home button to stop the app. If I comment out either one or both, I do not get any log messages. It seems that you need both methods for either to work. They don't even get called without the presence of the other.
When debugging in the iOS Simulator, (I don't know how to tell what version of the OS I'm using in the Simulator) I never get either of the log messages. If both methods are present, and only if both are present, I get "Warning: Unable to create restoration in progress marker file" showing up in my log, but I still don't get the log messages I made. So, the mere presence of both will cause a warning, but no force on Earth will allow them to be called. In the simulator. I tried adding a restoration id in the storyboard, but it didn't change anything.
I realize that Apple recommends running on an actual device and they don't guarantee similar behaviour on the simulator. But is there some setting I need to put somewhere to get state restoration working in the simulator? At one point I had it working, and I assumed that my storyboard changes had disrupted it. But with such a minimal app, I'm wondering if there is something more fundamental.
This is not a bug. These methods are called in preparation of state serialization for your app. State serialization never happens in the simulator because the app will not be terminated.
Ultimately, this is one of many differences between the simulator and actual devices. Always test on a device to ensure actual functionality.
Edit: State serialization can happen in the simulator by press the simulated 'home' key. ⌘⇧H
Often, the simulator start acting funny and the solution to most problem there is just to reset it.
In the simulator, click on the 'iOS Simulator menu' > 'Rest Content And Settings...'
I do this I think at least once a day, when the keyboard just stops responding or I get funny messages out of the blue.
Related
I am currently testing my Game Center Aware App using the Game Center Sandbox, with one instance running on the iOS simulator and the other on an Retina iPad Mini. I have a view controller which needs to receive turn events, so I implement the method
player:receivedTurnEventForMatch:didBecomeActive:
in the GKLocalPlayerListener protocol, which my UIViewController subclass adopts, and then register for events with this line
[[GKLocalPlayer localPlayer] registerListener: self];
in the init method of the view controller. However, despite the Game Center App saying that the two instances of the game have connected, this method is rarely called on the iPad, and I dont't think I've ever seen the simulator instance calling it. However, going to the Game Center App shows that both instances are updated, showing that both instances are capable of receiving the event. What could be causing this?
I had the same problem on iOS 7/Xcode 5/iPhone 5.
To fix that issue you need just add "Game Center" entitlement to your App ID. You can do that by navigating to project's "Capabilities" tab in Xcode.
Please note that player:receivedTurnEventForMatch:didBecomeActive: will be fired on devices only.
The workaround I found for this issue on the simulator is to call the
loadMatchDataWithCompletionHandler:
method when a refresh button is pushed in the UI, which causes match data to be loaded in the simulator.
When I tap my app icon to launch it, it takes 0.5-1.0 seconds after the tap before the app actually opens from the Springboard - in other words, there's a significant delay between tapping the icon and the Springboard zooming into the app's launch image. I'm not seeing this with any other apps on the device (iPad 3). This is also happening on the iPhone 4, but not the iPhone 5.
In addition to this happening on first launch, it also happens when the app is backgrounded.
I went through and made sure there wasn't anything expensive going on in applicationDidFinishLaunching or appBecameActive - I even tried deleting everything except assigning the view controller to the UIWindow's root view.
Has anyone ever seen anything like this before? Any ideas on how to fix it? Thanks!
If I read your statement
"significant delay between tapping the icon and...launch image"
then it's something that Springboard is dealing with. In other words, the delay is before your main() is called, so it's likely an issue with your app's static characteristics, either something declared in the info.plist or something with Springboard's ability to just load the app.
Some things I would check:
info.plist is well-formed and doesn't contain unnecessary references or other tags;
launch images are not crazy large;
the .ipa is not crazy large;
As xmlhack mentions, that you don't have something odd happening with static variables.
I've found at least one reason why there can be a delay. Provisioning profiles. Lots of them.
I've had more than 400 of them when I thought about it. Removed all old ones and AdHoc and developer builds start time returned back to normal.
I have nearly completed my first app. In testing on the device, I am getting a crash when I press the home button, with the error message
libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient:
Based on these posts:
https://stackoverflow.com/search?q=how+to+shut+down+OpenGL
OpenGL ES crash on move background, iOS 5.1
I am pretty sure the problem is that my app is an extension of software that uses some sample code involving OpenGL (about which I have very little understanding) and that the OpenGL tasks are not shutting down properly on resignActive.
I tried the following in my AppDelegate with no luck:
- (void)applicationWillResignActive:(UIApplication *)application {
glFinish();
}
My app does not need to save any settings upon exit... it just needs to end.
Can anyone suggest a solution?
I am now working on a Sprite Kit game and I had a similar problem.
Check if you have on the screen the node that tells the FPS, because that might be rendering and causing the crash.. It did for me.
In applicationWillResignActive method I call my pause method as all of you.
*edit - and check for audio playing
To finish program at user push home button ?
on Xcode, choice Target and select Info tab.
Custom iOS Target Properties, add a Key named
Application does not run in background
and set Value
YES
Try it!
p.s. Not necessary write glFinish().
As the title suggests, I have an app which uses Facebook connect to log users in.
On the iPhone this works fine; it switches to the Facebook app, logs in and then goes back to my app at the same place it left off.
However on an iPad (I only have an iPad 1 to hand but I'm presuming the problem is across all 3), when it returns to my app it seems to have restarted it entirely. It goes back to the splash screen, and then to the login screen. The user is stuck in an endless loop of "unsuccessfully" logging in, despite the fact that the Facebook app is logging in correctly.
Does anyone have any idea why this could be happening on the iPad but not an iPhone?
This app is actually inherited from a much older app which was iPhone only, and to simplify things it has essentially been left that way. The images etc are just scaled based on screen size, there is no differentiation in the code between iPhones and iPads other than their screen size. The facebook connect code has a "FBIsDeviceIPad" bool, but afaik that is just for setting the position and size of the popup login dialog when not using SSO.
Edit:
Further investigation suggests it could be an issue with OpenGL ES. The app crashes when sent to the background, as the OpenGl ES code carries on trying to animate etc. The facebook app momentarily puts my app into the background, ergo the app crashes and restarts.
I'll update this once I find out how to fix this, in the meantime if anyone has already dealt with this situation I would welcome any suggestions.
In your AppDelegate Class implement this code
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [facebook handleOpenURL:url];
}
For me, it was the permissions that made a difference. I had the same problem om the iPhone. and i reduced the permissions and the app stopped doing that.
Turns out it's a memory issue as noted in the question edit. Still not resolved how to get it working, but this is at least the cause of the problem.
I just set the 'Application does not run in background' parameter of my ios app to NO and I added the relevant refreshes in applicationDidBecomeActive: in my application delegate then it works pretty well. But when I switch back to my app, the splash screen still appear during one second. How to remove it and display directly the app ?
I though it was impossible, but it remembered me this topic : Prevent Splash Screen from showing after returning from background
It seems to include an answer to your question...
Also, don't forget to try on the device, sometimes the simulator does weird things.