What Is the Life Cycle of an iPhone Application

How does iphone application life cycle works in terms of development?

User launches application means that int main(int argc, char *argv[]) in main.m is invoked.

Everything else happens as a result of that main method, particularly the call to UIApplicationMain.

From the UIApplicationMain docs

This function instantiates the
application object from the principal
class and and instantiates the
delegate (if any) from the given class
and sets the delegate for the
application. It also sets up the main
event loop, including the
application’s run loop, and begins
processing events. If the
application’s Info.plist file
specifies a main nib file to be
loaded, by including the NSMainNibFile
key and a valid nib file name for the
value, this function loads that nib
file.

It's all explained there.

iOS app: Is there a life after crash and termination?

Doing any non async-safe task when the app crashed is highly NOT-recommendable!

  1. You are not allowed to allocate any new memory at that time
  2. You are only allowed to use async safe code (Any Objective-C code is NOT async safe)
  3. You need to take into account that memory is already corrupted
  4. You need to implement async-safe networking code
  5. and many many more reasons.

See these blog posts from Landon Fuller, the author of PLCrashReporter:

  1. http://landonf.bikemonkey.org/code/crashreporting/Reliable_Crash_Reporting_1.1.20130119.html
  2. http://landonf.bikemonkey.org/code/objc/Reliable_Crash_Reporting.20110912.html

You are trying to solve a problem, that is not a problem in the real world. People do restart their apps and will send the crash reports.

What part of the App Delegate life-cycle is called when an app in the foreground has an out of memory crash?

If the app crashes, no lifecycle method is called reliably. Instead you can create & register a global exception handler which gets invoked in this case:

func exceptionHandler(exception: NSException) {
print("*** UNHANDLED EXCEPTION ***")
print(exception)
print("CALL STACK:")
print(exception.callStackSymbols.joined(separator: "\n"))
}

Register this function using NSSetUncaughtExceptionHandler, e.g. in your UIApplicationDelegate.application:didFinishLaunchingWithOptions::

NSSetUncaughtExceptionHandler(exceptionHandler)

iOS app life cycle after long periods of time of inactivity


0x000000008badf00d

This is a hard coded error for the app watchdog. "Ate bad food".

It means that your app is being terminated on launch because it is taking too long for the application:didFinishLaunchingWithOptions: function to return.

My guess is that you're making a long core data call or network request in there.

The crash here is on startup though. Not a crash that's happening after a long period of time.

I suspect that your app is being terminated by the OS due to memory pressure from another app but then when launching the app is trying to continue doing something that it is no longer actually doing and getting stuck somewhere.

What does your application:didFinishLaunchingWithOptions: function do?

How to handle app lifecycle with Flutter (on Android and iOS)?

There is a method called when the system put the app in the background or return the app to foreground named didChangeAppLifecycleState.

Example with widgets:

  class _AppLifecycleReactorState extends State<AppLifecycleReactor> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}

AppLifecycleState _notification;

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
setState(() { _notification = state; });
}

@override
Widget build(BuildContext context) {
return new Text('Last notification: $_notification');
}
}

Also there are CONSTANTS to know the states that an application can be in, eg:

  1. inactive
  2. paused
  3. resumed
  4. suspending

The usage of these constants would be the value of the constant e.g:

const AppLifecycleState(state)



Related Topics



Leave a reply



Submit