- available since iOS2.0, a very important class that provides essential information about the Environment (Process, Computer hardware, OS), but MORE IMPORTANTLY, it also manage activities (long-time-running tasks).
- provides methods to access information about the current process. Each process has an agent (NSProcessInfo).
- returns arguments, environment variables, host name, process name, operating system !
- Process information
- Computer information
- Host information
- function: isOperatingSystemAtLeastVersion:
(majorVersion:int, minorVersion:int, patchVersion:int)
+ Managing Activities:
We can use methods to give hints to the system that your application has special requirements:
Use activities when performing long-running operations !!! 2 categories:
- User initiated: user explicitly started: exporting or downloading file – NSActivityUserInitiated
- Background: not by user: autosaving, indexing, …
Special category: NSActivitiyLatencyCritical – use for audio or video recording – which requires high priority!
If activities are synchronous inside an event callback on main thread -> no need to use this !
Also we can use this to control Automatic Termination:
id activity = [[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityAutomaticTerminationDisabled reason:@"Good Reason"];
// Perform some work.
[[NSProcessInfo processInfo] endActivity:activity];
This API also provides mechanism to disable system-wide & display idle-sleep. So it’s important to end activities that disable sleep.
To log out or shut down more quickly, system may kill applications instead of requesting them to quit. We can use:
- enableSuddenTermination: decrement counter
- disableSuddenTermination: increment counter
When we start the app, counter = 1. If counter == 0 -> safely killable.
If we have NSSupportsSuddenTermination = YES in application plist -> the app is killable right away (but still can disableSuddenTermination)
Disable Sudden Termination when: app usually have to do something before it terminates (saving), then we bracket these operations within disableSuddenTermination and enableSuddenTermination.
Some AppKit actually disable sudden termination for a time while performing saving operations:
- NSUserDefaults temporarily disables sudden termination to prevent process killing when that default is written to disk.
Thermal State: app should reduce system usage at high thermal states: register for NSProcessInfoThermalStateDidChangeNotification
to handle it.