I have an alarm app and it should never crash, but in the event that it does (especially in beta testing phase) is there a way to show a crash image? So an image that it goes to if the app crashes (but it stays in the app)? That way if it were worst case scenario and were to crash during the night, they may wake up, see the app's crashed screen and be saved from sleeping in.
If you use local notifications, and set one when the user sets the alarm, they'll get woken up matter what. If your app hasn't crashed then you can stop the notification from showing and raise the alarm in your own way. But if the app crashes or the user switches app then an alert view will pop up and you can set the sound to be made.
Related
This is a rather general question on what actually happens when an app returns from background. I have a user telling me that on opening my app that he has not used for over a day, he will still be shown the same view that he had before he closed the app (by "closed" I mean he just hit the home button to send it to background, NOT hold and then tap the cross button to kill the app completely).
I was on the impression that if an app is restored from the background after a long time, it will be reloaded completely (showing splash screen and everything), as in the cases when I opened facebook or gmail app after I haven't used it for some time.
So my question is, do I have to implement a check somewhere on the period of time passed since my app was sent to background and reset everything when it goes over a certain threshold, or is that supposed to be handled by iOS itself... and of course if a user sent my app to the background and return after 2 minutes I would not want to refresh
You might have to handle that in your appdelegate methods by setting a timestamp. Since multitasking is enabled in iPhones, it will start from the same screen again. An app can be in background for a long time until user decides to kill the app.
Some of the delegate methods are
- (void)applicationWillResignActive:(UIApplication *)iApplication;
- (void)applicationDidEnterBackground:(UIApplication *)iApplication;
- (void)applicationWillEnterForeground:(UIApplication *)iApplication;
- (void)applicationDidBecomeActive:(UIApplication *)iApplication;
If you want to disable multitasking you can do that by setting a UIApplicationExistsOnSuspend key in application plist. But that will make the app quit immediately when user presses home button.
The decision on whether your app should refresh after some period of time in the background is completely up to you and the needs of your app. An app could sit in the background for weeks without being killed by the OS. Or it could be killed seconds after going into the background. It all depends on resources being needed for other running apps.
If you want logic in your app that makes it restart after 24 hours, for example, then it is up to you to write code to handle this. Save a timestamp when the app goes into the background. When it returns to the foreground, compare the current time to the saved timestamp. If enough time has passed, you need to update your UI to reflect whatever desired state you want to show the user.
My game made using cocos2d crashes on iOS5 after resuming from the background when left for a while. I want to know what the standard/best practice is, on handling an app that is sent to the background. Do I terminate it after a certain time? I see some games pull up a loading screen when you resume it after a long time but when you resume it immediately it goes straight to the game. What are they loading when they resume?
Any pointers in the right direction would be much appreciated.
Thanks
AC
You can opt out of background execution by adding UIApplicationExitsOnSuspend to your Info.plist.
Other than that it really is your job to ensure that your app doesn't crash when it resumes execution. You have to understand that your application basically enters a suspended state. That means it should unload all unneeded resources, otherwise the system may terminate your app's process.
In your app delegate you should respond to the applicationDidBecomeActive message and respond accordingly so that your app is able to resume execution without any issues. This can include loading any unloaded assets and checking if system settings (ie. locale, Game Center user, etc.) have changed.
You can also register a didBecomeActive UINotification so that any class in your app gets notified when the app should resume.
i try to retrieve Calendar events between two dates. After that I try to delete all events. this program is working fine. The Events deleting process will take few second/minute based on number of events.
When device goes to sleep this application will work in background as usual. After coming to normal state(wake up) my application will exit. But, i did over come this problem, disable idle time.
But this same problem repeating when i press sleep/wake up button on the top of iPhone. How to over come this problem. What happens in my application, when changing state, any memory problem or any other...
When the sleep/wake button is pressed, your application is sent to the background/changes mode to inactive. Check UIApplicationDelegate documentation applicationWillResignActive: and applicationDidEnterBackground:. When this happens there are restrictions about your application doing background operations, which are described within the documentation.
I am developing an iPhone app that delivers alerts at certain times using UILocalNotifications. Pressing the OK button on the alert launches the app so it can perform specific tasks.
So far, everything works beautifully in most cases: if the app is running and the alert fires, it works fine, and if the app is not running (but the phone is on), it works just as well.
However, if the alert fires when the screen is locked, one of two things happens.
alert fires, and I "slide to unlock" immediately, then the app launches as expected.
alert fires, but I wait to "slide to unlock" longer than 20 seconds (the time it takes the screen to lock (dim) again). When I finally unlock the screen, the alert shows, but does NOT launch the app.
I have looked throughout the Apple docs and this site, but cannot find an answer. I hope my explanation makes sense. Any thoughts?
I think that behaviour makes sense and shouldn't be circumvented (which I think is not possible). If the user slides to unlock just after a few seconds after the notification, the propability is high, that he slided to unlock just because of that notification and wants to get into the app. If a lot of time is passed, the notification is still shown, but the propability is low, that the user slides to unlock because of this notification. It is more likely that he just wants to write an email or do something completely different. So the app of the last notification shouldn't get started.
Thanks for your quick and clear answer, Dominik. Quick follow-up: the purpose in relaunching the app is to schedule another alert. If I send several alerts at once (scheduled for different times), and the user does not unlock the phone for any of them, do they all appear at the same time the first time the user unlocks? (I would only want the last one to appear)
Thanks again.
My App needs a Internet Connection which is checkt in the ViewDidLoad if there is no Internet connection I want to terminate the app when the Home Button is clickt so that the app start in its initial state next time but only in this case.
If there is a Internet connection from the start the homeButton should bring the app just to the background.
Apple does strongly discourages quitting from application programmatically.
I think you can handle your case without quitting application - when application goes to background(in applicationDidEnterBackground method of application delegate) save some flag indicating that you want to reinit it on resume, then when application comes back to foreground (applicationWillEnterForeground method in delegate) apply your initialization logic in case flag is set.
Programatically terminate an App is a behaviour that will be rejected to be published in the AppStore, as it seems that the application crashed.
If you don't mind that your application will never see the light at the AppStore, you can simply use exit(0).
When your app does not find an internet connection, switch to a view that exactly imitates your Default start-up image, then force that view to stay visible the usual amount of start-up time after any call to making your app active. You can also kill and recreate fresh all your other MVC objects during this time.
That way, no one will know that your app wasn't freshly started when brought back from the background.