public final class NSActivityOptions
extends java.lang.Object
These activities can be used when your application is performing a long-running operation. If the activity can take different amounts of time (for example, calculating the next move in a chess game), it should use this API. This will ensure correct behavior when the amount of data or the capabilities of the user's computer varies. You should put your activity into one of two major categories:
User initiated: These are finite length activities that the user has explicitly started. Examples include exporting or downloading a user specified file.
Background: These are finite length activities that are part of the normal operation of your application but are not explicitly started by the user. Examples include autosaving, indexing, and automatic downloading of files.
In addition, if your application requires high priority IO, you can include the 'NSActivityLatencyCritical' flag (using a bitwise or). This should be reserved for activities like audio or video recording.
If your activity takes place synchronously inside an event callback on the main thread, you do not need to use this API.
Be aware that failing to end these activities for an extended period of time can have significant negative impacts to the performance of your user's computer, so be sure to use only the minimum amount of time required. User preferences may override your application’s request.
This API can also be used to control auto termination or sudden termination.
id activity = [NSProcessInfo.processInfo beginActivityWithOptions:NSActivityAutomaticTerminationDisabled reason:@"Good Reason"]; // work [NSProcessInfo.processInfo endActivity:activity];
is equivalent to:
[NSProcessInfo.processInfo disableAutomaticTermination:@"Good Reason"]; // work [NSProcessInfo.processInfo enableAutomaticTermination:@"Good Reason"]
Since this API returns an object, it may be easier to pair begins and ends. If the object is deallocated before the -endActivity: call, the activity will be automatically ended.
This API also provides a mechanism to disable system-wide idle sleep and display idle sleep. These can have a large impact on the user experience, so be sure not to forget to end activities that disable sleep (including NSActivityUserInitiated).
| Modifier and Type | Field and Description |
|---|---|
static long |
AutomaticTerminationDisabled
Prevents automatic termination.
|
static long |
Background
App has initiated some kind of work, but not as the direct result of user request.
|
static long |
IdleDisplaySleepDisabled
Used for activities that require the screen to stay powered on.
|
static long |
IdleSystemSleepDisabled
Used for activities that require the computer to not idle sleep.
|
static long |
LatencyCritical
Used for activities that require the highest amount of timer and I/O precision available.
|
static long |
SuddenTerminationDisabled
Prevents sudden termination.
|
static long |
UserInitiated
App is performing a user-requested action.
|
static long |
UserInitiatedAllowingIdleSystemSleep
App is performing a user-requested action.
|
public static final long IdleDisplaySleepDisabled
public static final long IdleSystemSleepDisabled
public static final long SuddenTerminationDisabled
public static final long AutomaticTerminationDisabled
public static final long UserInitiated
public static final long UserInitiatedAllowingIdleSystemSleep
public static final long Background
public static final long LatencyCritical