Mac Developer Library

Developer

AppKit Framework Reference NSApplicationDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSApplicationDelegate

The NSApplicationDelegate protocol defines the methods that may be implemented by delegates of NSApplication objects.

Inheritance


Not Applicable

Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.6 and later.
  • Sent to notify the delegate that the application is about to terminate.

    Declaration

    Swift

    optional func applicationShouldTerminate(_ sender: NSApplication) -> NSApplicationTerminateReply

    Objective-C

    - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender

    Parameters

    sender

    The application object that is about to be terminated.

    Return Value

    One of the values defined in NSApplicationTerminateReply constants indicating whether the application should terminate. For compatibility reasons, a return value of NOfalse is equivalent to NSTerminateCancel, and a return value of YEStrue is equivalent to NSTerminateNow.

    Discussion

    This method is called after the application’s Quit menu item has been selected, or after the terminate: method has been called. Generally, you should return NSTerminateNow to allow the termination to complete, but you can cancel the termination process or delay it somewhat as needed. For example, you might delay termination to finish processing some critical data but then terminate the application as soon as you are done by calling the replyToApplicationShouldTerminate: method.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Invoked when the user closes the last window the application has open.

    Declaration

    Swift

    optional func applicationShouldTerminateAfterLastWindowClosed(_ theApplication: NSApplication) -> Bool

    Objective-C

    - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication

    Parameters

    theApplication

    The application object whose last window was closed.

    Return Value

    NOfalse if the application should not be terminated when its last window is closed; otherwise, YEStrue to terminate the application.

    Discussion

    The application sends this message to your delegate when the application’s last window is closed. It sends this message regardless of whether there are still panels open. (A panel in this case is defined as being an instance of NSPanel or one of its subclasses.)

    If your implementation returns NOfalse, control returns to the main event loop and the application is not terminated. If you return YEStrue, your delegate’s applicationShouldTerminate: method is subsequently invoked to confirm that the application should be terminated.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Sent by the default notification center immediately before the application terminates.

    Declaration

    Swift

    optional func applicationWillTerminate(_ aNotification: NSNotification)

    Objective-C

    - (void)applicationWillTerminate:(NSNotification *)aNotification

    Parameters

    aNotification

    A notification named NSApplicationWillTerminateNotification. Calling the object method of this notification returns the NSApplication object itself.

    Discussion

    Your delegate can use this method to perform any final cleanup before the application terminates.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Sent by the default notification center immediately before the application object updates its windows.

    Declaration

    Swift

    optional func applicationWillUpdate(_ aNotification: NSNotification)

    Objective-C

    - (void)applicationWillUpdate:(NSNotification *)aNotification

    Parameters

    aNotification

    A notification named NSApplicationWillUpdateNotification. Calling the object method of this notification returns the NSApplication object itself.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

    See Also

    – applicationDidUpdate:
    updateWindows (NSApplication)

  • Sent by the default notification center immediately after the application object updates its windows.

    Declaration

    Swift

    optional func applicationDidUpdate(_ aNotification: NSNotification)

    Objective-C

    - (void)applicationDidUpdate:(NSNotification *)aNotification

    Parameters

    aNotification

    A notification named NSApplicationDidUpdateNotification. Calling the object method of this notification returns the NSApplication object itself.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

    See Also

    – applicationWillUpdate:
    updateWindows (NSApplication)

  • Sent by the application to the delegate prior to default behavior to reopen (rapp) AppleEvents.

    Declaration

    Swift

    optional func applicationShouldHandleReopen(_ theApplication: NSApplication, hasVisibleWindows flag: Bool) -> Bool

    Objective-C

    - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag

    Parameters

    theApplication

    The application object.

    flag

    Indicates whether the NSApplication object found any visible windows in your application. You can use this value as an indication of whether the application would do anything if you return YEStrue.

    Return Value

    YEStrue if you want the application to perform its normal tasks or NOfalse if you want the application to do nothing.

    Discussion

    These events are sent whenever the Finder reactivates an already running application because someone double-clicked it again or used the dock to activate it.

    By default the Application Kit will handle this event by checking whether there are any visible NSWindow (not NSPanel) objects, and, if there are none, it goes through the standard untitled document creation (the same as it does if theApplication is launched without any document to open). For most document-based applications, an untitled document will be created.

    The application delegate will also get a chance to respond to the normal untitled document delegate methods. If you implement this method in your application delegate, it will be called before any of the default behavior happens. If you return YEStrue, then NSApplication will proceed as normal. If you return NOfalse, then NSApplication will do nothing. So, you can either implement this method with a version that does nothing, and return NOfalse if you do not want anything to happen at all (not recommended), or you can implement this method, handle the event yourself in some custom way, and return NOfalse.

    Miniaturized windows, windows in the Dock, are considered visible by this method, and cause flag to return YEStrue, despite the fact that miniaturized windows return NOfalse when sent an isVisible message.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Allows the delegate to supply a dock menu for the application dynamically.

    Declaration

    Swift

    optional func applicationDockMenu(_ sender: NSApplication) -> NSMenu?

    Objective-C

    - (NSMenu *)applicationDockMenu:(NSApplication *)sender

    Parameters

    sender

    The application object associated with the delegate.

    Return Value

    The menu to display in the dock.

    Discussion

    You can also connect a menu in Interface Builder to the dockMenu outlet. A third way for your application to specify a dock menu is to provide an NSMenu in a nib.

    If this method returns a menu, this menu takes precedence over the dockMenu in the nib.

    The target and action for each menu item are passed to the dock. On selection of the menu item the dock messages your application, which should invoke [NSApp sendAction:selector to:target from:nil].

    To specify an NSMenu in a nib, you add the nib name to the info.plist, using the key AppleDockMenu. The nib name is specified without an extension. You then create a connection from the file’s owner object (which by default is NSApplication) to the menu. Connect the menu to the dockMenu outlet of NSApplication. The menu is in its own nib file so it can be loaded lazily when the dockMenu is requested, rather than at launch time.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.1 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Sent to the delegate before the specified application presents an error message to the user.

    Declaration

    Swift

    optional func application(_ application: NSApplication, willPresentError error: NSError) -> NSError

    Objective-C

    - (NSError *)application:(NSApplication *)application willPresentError:(NSError *)error

    Parameters

    application

    The application object associated with the delegate.

    error

    The error object that is used to construct the error message. Your implementation of this method can return a new NSError object or the same one in this parameter.

    Return Value

    The error object to display.

    Discussion

    You can implement this delegate method to customize the presentation of any error presented by your application, as long as no code in your application overrides either of the NSResponder methods presentError:modalForWindow:delegate:didPresentSelector:contextInfo: or presentError: in a way that prevents errors from being passed down the responder chain to the application object.

    Your implementation of this delegate method can examine error and, if its localized description or recovery information is unhelpfully generic, return an error object with specific localized text that is more suitable for presentation in alert sheets and dialogs. If you do this, always use the domain and error code of the NSError object to distinguish between errors whose presentation you want to customize and those you do not. Don’t make decisions based on the localized description, recovery suggestion, or recovery options because parsing localized text is problematic. If you decide not to customize the error presentation, just return the passed-in error object.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Sent by the default notification center when the configuration of the displays attached to the computer is changed (either programmatically or when the user changes settings in the Displays control panel).

    Declaration

    Swift

    optional func applicationDidChangeScreenParameters(_ aNotification: NSNotification)

    Objective-C

    - (void)applicationDidChangeScreenParameters:(NSNotification *)aNotification

    Parameters

    aNotification

    A notification named NSApplicationDidChangeScreenParametersNotification. Calling the object method of this notification returns the NSApplication object itself.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate to open a single file.

    Declaration

    Swift

    optional func application(_ theApplication: NSApplication, openFile filename: String) -> Bool

    Objective-C

    - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename

    Parameters

    theApplication

    The application object associated with the delegate.

    filename

    The name of the file to open.

    Return Value

    YEStrue if the file was successfully opened or NOfalse if it was not.

    Discussion

    Sent directly by theApplication to the delegate. The method should open the file filename, returning YEStrue if the file is successfully opened, and NOfalse otherwise. If the user started up the application by double-clicking a file, the delegate receives the application:openFile: message before receiving applicationDidFinishLaunching:. (applicationWillFinishLaunching: is sent before application:openFile:.)

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate to open a file programmatically.

    Declaration

    Swift

    optional func application(_ sender: AnyObject, openFileWithoutUI filename: String) -> Bool

    Objective-C

    - (BOOL)application:(id)sender openFileWithoutUI:(NSString *)filename

    Parameters

    sender

    The object that sent the command.

    filename

    The name of the file to open.

    Return Value

    YEStrue if the file was successfully opened or NOfalse if it was not.

    Discussion

    Sent directly by sender to the delegate to request that the file filename be opened as a linked file. The method should open the file without bringing up its application’s user interface—that is, work with the file is under programmatic control of sender, rather than under keyboard control of the user.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate to open a temporary file.

    Declaration

    Swift

    optional func application(_ theApplication: NSApplication, openTempFile filename: String) -> Bool

    Objective-C

    - (BOOL)application:(NSApplication *)theApplication openTempFile:(NSString *)filename

    Parameters

    theApplication

    The application object associated with the delegate.

    filename

    The name of the temporary file to open.

    Return Value

    YEStrue if the file was successfully opened or NOfalse if it was not.

    Discussion

    Sent directly by theApplication to the delegate. The method should attempt to open the file filename, returning YEStrue if the file is successfully opened, and NOfalse otherwise.

    By design, a file opened through this method is assumed to be temporary—it’s the application’s responsibility to remove the file at the appropriate time.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate to open multiple files.

    Declaration

    Swift

    optional func application(_ sender: NSApplication, openFiles filenames: [AnyObject])

    Objective-C

    - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames

    Parameters

    sender

    The application object associated with the delegate.

    filenames

    An array of NSString objects containing the names of the files to open..

    Discussion

    Identical to application:openFile: except that the receiver opens multiple files corresponding to the file names in the filenames array. Delegates should invoke the replyToOpenOrPrint: method upon success or failure, or when the user cancels the operation.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate to open an untitled file.

    Declaration

    Swift

    optional func applicationOpenUntitledFile(_ theApplication: NSApplication) -> Bool

    Objective-C

    - (BOOL)applicationOpenUntitledFile:(NSApplication *)theApplication

    Parameters

    theApplication

    The application object associated with the delegate.

    Return Value

    YEStrue if the file was successfully opened or NOfalse if it was not.

    Discussion

    Sent directly by theApplication to the delegate to request that a new, untitled file be opened.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Invoked immediately before opening an untitled file.

    Declaration

    Swift

    optional func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool

    Objective-C

    - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender

    Parameters

    sender

    The application object associated with the delegate.

    Return Value

    YEStrue if the application should open a new untitled file or NOfalse if it should not.

    Discussion

    Use this method to decide whether the application should open a new, untitled file. Note that applicationOpenUntitledFile: is invoked if this method returns YEStrue.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Sent when the user starts up the application on the command line with the -NSPrint option.

    Declaration

    Swift

    optional func application(_ theApplication: NSApplication, printFile filename: String) -> Bool

    Objective-C

    - (BOOL)application:(NSApplication *)theApplication printFile:(NSString *)filename

    Parameters

    theApplication

    The application object that is handling the printing.

    filename

    The name of the file to print.

    Return Value

    YEStrue if the file was successfully printed or NOfalse if it was not.

    Discussion

    This message is sent directly by theApplication to the delegate. The application terminates (using the terminate: method) after this method returns.

    If at all possible, this method should print the file without displaying the user interface. For example, if you pass the -NSPrint option to the TextEdit application, TextEdit assumes you want to print the entire contents of the specified file. However, if the application opens more complex documents, you may want to display a panel that lets the user choose exactly what they want to print.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Prints a group of files.

    Declaration

    Swift

    optional func application(_ application: NSApplication, printFiles fileNames: [AnyObject], withSettings printSettings: [NSObject : AnyObject], showPrintPanels showPrintPanels: Bool) -> NSApplicationPrintReply

    Objective-C

    - (NSApplicationPrintReply)application:(NSApplication *)application printFiles:(NSArray *)fileNames withSettings:(NSDictionary *)printSettings showPrintPanels:(BOOL)showPrintPanels

    Parameters

    application

    The application object that is handling the printing.

    fileNames

    An array of NSString objects, each of which contains the name of a file to print.

    printSettings

    A dictionary containing NSPrintInfo-compatible print job attributes.

    showPrintPanels

    A Boolean that specifies whether the print panel should be displayed for each file printed. Print progress indicators will be presented even if this value is NOfalse.

    Return Value

    A constant indicating whether printing was successful. For a list of possible values, see NSApplicationPrintReply.

    Discussion

    Return NSPrintingReplyLater if the result of printing cannot be returned immediately, for example, if printing will cause the presentation of a sheet. If your method returns NSPrintingReplyLater it must always invoke the NSApplication method replyToOpenOrPrint:] when the entire print operation has been completed, successfully or not.

    This delegate method replaces application:printFiles:, which is now deprecated. If your application delegate only implements the deprecated method, it is still invoked, and NSApplication uses private functionality to arrange for the print settings to take effect.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Sent to the delegate when Apple Push Services successfully completes the registration process.

    Declaration

    Swift

    optional func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)

    Objective-C

    - (void)application:(NSApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

    Parameters

    application

    The application that initiated the remote-notification registration process.

    deviceToken

    A token that identifies the device to Apple Push Notification Service (APNS). The token is an opaque data type because that is the form that the provider needs to submit to the APNS servers when it sends a notification to a device. The APNS servers require a binary format for performance reasons.

    The size of a device token is 32 bytes.

    Discussion

    The delegate receives this message after the registerForRemoteNotificationTypes:method of NSApplication is invoked and there is no error in the registration process. After receiving the device token, the application should connect with its provider and give the token to it. APNS only pushes notifications to the application’s computer that are accompanied with this token.

    For more information about how to implement push notifications in your application, see Local and Remote Notification Programming Guide.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Sent to the delegate when Apple Push Service cannot successfully complete the registration process.

    Declaration

    Swift

    optional func application(_ application: NSApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError)

    Objective-C

    - (void)application:(NSApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error

    Parameters

    application

    The application that initiated the remote-notification registration process.

    error

    An NSError object that encapsulates information why registration did not succeed. The application can display this information to the user.

    Discussion

    The delegate receives this message after the registerForRemoteNotificationTypes: method of NSApplication is invoked and there is an error in the registration process.

    For more information about how to implement push notifications in your application, see Local and Remote Notification Programming Guide.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Sent to the delegate when a running application receives a remote notification.

    Declaration

    Swift

    optional func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject])

    Objective-C

    - (void)application:(NSApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

    Parameters

    application

    The application that received the remote notification.

    userInfo

    A dictionary that contains information related to the remote notification, specifically a badge number for the application icon, a notification identifier, and possibly custom data. The provider originates it as a JSON-defined dictionary that AppKit converts to an NSDictionary object; the dictionary may contain only property-list objects plus NSNull.

    Discussion

    The delegate receives this message when the application is running and a remote notification arrives for it. In response, the application typically connects with its provider and downloads the data waiting for it. It may also process the notification in any other way it deems useful.

    The userInfo dictionary contains another dictionary that you can obtain using the aps key. You can access the contents of the aps dictionary using the following keys:

    • badge—A number indicating the quantity of data items to obtain from the provider. This number is to be displayed on the application icon. The absence of a badge property indicates that any number currently badging the icon should be removed.

      Icon badging is the only notification type supported for non-running applications.

    • alert—The value may either be a string for the alert message or a dictionary with two keys: body and show-view. The value of the former is the alert message and the latter is a Boolean (false or true). You may ignore the second key.

    • sound—The name of a sound file in the application bundle to play as an alert sound. If “default” is specified, the default sound should be played.

    The userInfo dictionary may also have custom data defined by the provider according to the JSON schema. The properties for custom data should be specified at the same level as the aps dictionary. However, custom-defined properties should not be used for mass data transport because there is a strict size limit per notification (256 bytes) and delivery is not guaranteed.

    If you implement applicationDidFinishLaunching: and a push notification for the application has recently arrived, this method is not invoked for that push notification. In this case, you can access the JSON data in the userInfo dictionary of the passed-in NSNotification object.

    For more information about how to implement push notifications in your application, see Local and Remote Notification Programming Guide.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Tells the delegate the user wants to continue an activity in your app.

    Declaration

    Swift

    optional func application(_ application: NSApplication, willContinueUserActivityWithType userActivityType: String) -> Bool

    Objective-C

    - (BOOL)application:(NSApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType

    Parameters

    application

    The app continuing the user activity.

    userActivityType

    The type of activity to be continued.

    Return Value

    YEStrue if you notify the user that your app is about to continue the activity or NOfalse if you want AppKit to notify the user.

    Discussion

    Use this method to provide immediate feedback to the user that an activity is about to continue on this device. The app calls this method as soon as the user confirms that an activity should be continued but possibly before the data associated with that activity is available.

    This method is called on the main thread as soon as the user indicates they want to continue an activity in your app. The NSUserActivity object may not be available instantly, so use this as an opportunity to show the user that an activity will be continued shortly and return YEStrue. If you leave this method unimplemented or return NOfalse, AppKit displays a default indication.

    For each invocation of this method, the app delegate is guaranteed to get exactly one invocation of application:continueUserActivity:restorationHandler: on success, or application:didFailToContinueUserActivityWithType:error: if an error was encountered.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Tells the delegate that the data for continuing an activity is available.

    Declaration

    Swift

    optional func application(_ application: NSApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler restorationHandler: ([AnyObject]!) -> Void) -> Bool

    Objective-C

    - (BOOL)application:(NSApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler

    Parameters

    application

    The app continuing the user activity.

    userActivity

    The activity object containing the data associated with the task the user was performing. Use the data in this object to recreate what the user was doing.

    restorationHandler

    A block to execute if your app creates or fetches objects to perform the task. Calling this block is optional and is only needed when specific objects are capable of continuing the activity. You can copy this block and call it at a later time. When calling a saved copy of the block, you must call it from the app’s main thread. This block has no return value and takes the following parameter:

    restorableObjects

    An array of NSResponder or NSDocument objects that you created or fetched in order to perform the operation. The system calls the restoreUserActivityState: method of each object in the array to perform the operation.

    Return Value

    YEStrue if this method handled continuing the activity; NOfalse to have AppKit attempt to continue the activity.

    Discussion

    The app calls this method when it receives the data associated with the user activity. Use the data stored in the NSUserActivity object to re-create the user’s activity. This method is your opportunity to update your app so that it can perform the associated task.

    If this user activity object was created automatically by having NSUbiquitousDocumentUserActivityType in a CFBundleDocumentTypes entry, AppKit can automatically restore the NSUserActivity on OS X if this method returns NOfalse, or if it is unimplemented. It does this by creating a document of the appropriate type using the URL stored in the userInfo dictionary under the NSUserActivityDocumentURLKey. The system calls the NSDocument method restoreUserActivityState: on the document.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Tells the delegate that the activity could not be continued.

    Declaration

    Swift

    optional func application(_ application: NSApplication, didFailToContinueUserActivityWithType userActivityType: String, error error: NSError)

    Objective-C

    - (void)application:(NSApplication *)application didFailToContinueUserActivityWithType:(NSString *)userActivityType error:(NSError *)error

    Parameters

    application

    The app that attempted to continue the activity.

    userActivityType

    The activity type that was attempted.

    error

    An error object indicating the reason for the failure.

    Discussion

    Use this method to let the user know that the specified activity could not be continued. If you do not implement this method, AppKit displays an error to the user with an appropriate message about the reason for the failure.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Tells the delegate that the user activity object has been updated.

    Declaration

    Swift

    optional func application(_ application: NSApplication, didUpdateUserActivity userActivity: NSUserActivity)

    Objective-C

    - (void)application:(NSApplication *)application didUpdateUserActivity:(NSUserActivity *)userActivity

    Parameters

    application

    The shared app object.

    userActivity

    The user activity object that was updated.

    Discussion

    This method is called when any user activity managed by AppKit has been updated. Use this as a last chance to add additional data to the user activity object.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Tells the delegate the application’s occlusion state changed.

    Declaration

    Swift

    optional func applicationDidChangeOcclusionState(_ notification: NSNotification)

    Objective-C

    - (void)applicationDidChangeOcclusionState:(NSNotification *)notification

    Parameters

    notification

    A notification named NSApplicationDidChangeOcclusionStateNotification. Calling the object method of this notification returns the NSApplication object itself.

    Discussion

    Upon receiving this method, you can query the application for its occlusion state. Note that this only notifies about changes in the state of the occlusion, not when the occlusion region changes. You can use this method to increase responsiveness and save power by halting any expensive calculations that the user can not see.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.9 and later.