iOS Guides | Samples

MonoTouch.UIKit.UIApplicationDelegate Class

A class used to receive events raised by a UIApplication.

See Also: UIApplicationDelegate

Syntax

[MonoTouch.Foundation.Model]
[MonoTouch.Foundation.Protocol]
[MonoTouch.Foundation.Register("UIApplicationDelegate", false)]
public class UIApplicationDelegate : NSObject, IUIApplicationDelegate, IDisposable

Remarks

A strongly typed implementation of a class that can be used to respond to events raised by the UIApplication.

Application developers will generally override the UIApplicationDelegate.FinishedLaunching method, configure the application's main UIWindow, instantiate the top-level UIViewController, and assign it to the UIWindow.RootViewController.

This is what a minimal UIApplicationDelegate class looks like:

C# Example

[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
	UIWindow window;

	public override bool FinishedLaunching (UIApplication app, NSDictionary options)
	{
		window = new UIWindow (UIScreen.MainScreen.Bounds);
		window.RootViewController = new UIViewController ();
		window.MakeKeyAndVisible ();
		
		return true;
	}
}
Operation
UIApplicationDelegate and the Application Lifecycle

The UIApplicationDelegate provides overridable methods for the entire application lifecycle:

Applications have four major modes:

As mentioned previously, the most commonly overridden method is UIApplicationDelegate.FinishedLaunching, which is the standard place to initialize the application's UIWindow and that window's UIWindow.RootViewController.

iOS applications should be designed to be long-lived, with many transitions between foreground processing and being suspended or backgrounded.

Assigning a UIApplicationDelegate

The UIApplicationDelegate of an application is typically set as one of few, or only, things done by the application's Main method. The UIApplicationDelegate exports a string using the RegisterAttribute and this string is used as the delegateClassName argument to the UIApplication.Main(string[],string,string) method, as shown in the following example:

C# Example

public class Application 
{
		static void Main(string[] args)
		{
			UIApplication.Main(args, null, "AppDelegate");
		}
	}

[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
//...etc
}

Application's that are launched from a XIB or storyboard use the UIApplicationDelegate specified in the XIB or storyboard.

Related content

Requirements

Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0

The members of MonoTouch.UIKit.UIApplicationDelegate are listed below.

See Also: NSObject

Public Constructors

Default constructor that initializes a new instance of this class with no parameters.
A constructor that initializes the object from the data stored in the unarchiver object.
Constructor to call on derived classes to skip initialization and merely allocate the object.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

Public Properties

WindowUIWindow. The window used to display the app on the device's main screen.

Public Methods

AccessibilityPerformMagicTap() : Boolean
Performs the most important action of the app. Often, this is toggling the most important state of the app.
ApplicationSignificantTimeChange(UIApplication)
Indicates a significant shift in time, such as midnight, carrier-changed time, or the start or stop of Daylight Savings.
ChangedStatusBarFrame(UIApplication, RectangleF)
Indicates that the UIView.Frame of the status bar has changed.
ContinueUserActivity(UIApplication, NSUserActivity, UIApplicationRestorationHandler) : Boolean
Informs the app that there is data associated with continuing a task specified as a NSUserActivity object, and then returns whether the app continued the activity.
DidChangeStatusBarOrientation(UIApplication, UIInterfaceOrientation)
Indicates that the orientation of the status bar has changed.
DidDecodeRestorableState(UIApplication, NSCoder)
Indicates that the app should restore highest-level state.
DidEnterBackground(UIApplication)
Indicates that the application has entered the background.
DidFailToContinueUserActivitiy(UIApplication, String, NSError)
Informs the app that the activity of the userActivityType type could not be continued, and specifies a error as the reason for the failure.
DidReceiveRemoteNotification(UIApplication, NSDictionary, Action<UIBackgroundFetchResult>)
Remote background notification support: Invoked by operating system when your application received a remote notification.
DidRegisterUserNotificationSettings(UIApplication, UIUserNotificationSettings)
Informs the app of the type of notifications it can use, as a UIUserNotificationSettings object.
FailedToRegisterForRemoteNotifications(UIApplication, NSError)
Indicates that a call to UIApplication.RegisterForRemoteNotifications failed.
FinishedLaunching(UIApplication)
Method invoked after the application has launched to configure the main window and view controller.
FinishedLaunching(UIApplication, NSDictionary) : Boolean
Method invoked after the application has launched to configure the main window and view controller.
GetSupportedInterfaceOrientations(UIApplication, UIWindow) : UIInterfaceOrientationMask
Returns a bit-mask of supported orientations for the specified forWindow.
GetViewController(UIApplication, String[], NSCoder) : UIViewController
Retrieve the UIViewController identified by the restorationIdentifierComponents.
HandleAction(UIApplication, String, NSDictionary, Action)
Informs the app of a custom action to perform based on a push notification, and includes the actionIdentifier value, remoteNoticationInfo data from the notification, and completionHandler for the app developer to run after performing the action.
HandleAction(UIApplication, String, UILocalNotification, Action)
Informs the app that the user selected an action identified by the actionIdentifier value from an alert of a UILocalNotification object, and executes the completionHandler block after it completes the action.
HandleAction(UIApplication, String, NSDictionary, NSDictionary, Action)
Informs the app of a custom action to perform based on a remote notification, and includes the actionIdentifier value, remoteNoticationInfo data from the notification, and completionHandler for the app developer to run after performing the action.
HandleAction(UIApplication, String, UILocalNotification, NSDictionary, Action)
Informs the app of a custom action to perform based on a local notification, and includes the actionIdentifier value, responseInfo data from the notification, and completionHandler for the app developer to run after performing the action.
HandleEventsForBackgroundUrl(UIApplication, String, NSAction)
Raised when events relating to a background NSUrlSession are waiting to be processed.
HandleOpenURL(UIApplication, NSUrl) : Boolean
Application developers should not use this deprecated method but use UIApplicationDelegate.OpenUrl instead.
HandleWatchKitExtensionRequest(UIApplication, NSDictionary, Action<MonoTouch.Foundation.NSDictionary>)
A watchkit extension has made a request.
OnActivated(UIApplication)
Called when the application is launched and every time the app returns to the foreground.
OnResignActivation(UIApplication)
Called when the application is about to enter the background, be suspended, or when the user receives an interruption such as a phone call or text.
OpenUrl(UIApplication, NSUrl, NSDictionary) : Boolean
Indicates that the application should open the specified url with context from options.
OpenUrl(UIApplication, NSUrl, UIApplicationOpenUrlOptions) : Boolean
Indicates that the application should open the specified url according to options.
OpenUrl(UIApplication, NSUrl, String, NSObject) : Boolean
Indicates that the application should open the specified url.
PerformActionForShortcutItem(UIApplication, UIApplicationShortcutItem, UIOperationHandler)
Called by the system when the user initiates a Home screen quick action, unless the interaction was handled in UIApplicationDelegate.WillFinishLaunching or UIApplicationDelegate.DidFinishLaunching.
PerformFetch(UIApplication, Action<UIBackgroundFetchResult>)
Background support: Invoked by the operating system to allow an application to download data.
ProtectedDataDidBecomeAvailable(UIApplication)
Indicates that the device was unlocked and previously-encrypted data is now available.
ProtectedDataWillBecomeUnavailable(UIApplication)
Indicates that the device is being locked and that protected files will become unavailable.
ReceivedLocalNotification(UIApplication, UILocalNotification)
Indicates that the application received a UILocalNotification.
ReceivedRemoteNotification(UIApplication, NSDictionary)
Indicates that the application received a remote notification.
ReceiveMemoryWarning(UIApplication)
The app has received a low-memory warning from the system.
RegisteredForRemoteNotifications(UIApplication, NSData)
Indicates that a call to UIApplication.RegisterForRemoteNotifications succeeded.
ShouldAllowExtensionPointIdentifier(UIApplication, NSString) : Boolean
Requests permission from the app to run app extensions based on the extension point identified by extensionPointIdentifier.
ShouldRequestHealthAuthorization(UIApplication)
The system calls this method when the developer's app should ask the user for access to HealthKit data.
ShouldRestoreApplicationState(UIApplication, NSCoder) : Boolean
Whether the application should restore saved state information.
ShouldSaveApplicationState(UIApplication, NSCoder) : Boolean
Whether the application should save application state information.
UserActivityUpdated(NSUserActivity)
Informs the app that the NSUserActivity object in userActivity has been updated.
UserActivityUpdated(UIApplication, NSUserActivity)
A user activity was updated.
UserDidAcceptCloudKitShare(UIApplication, CKShareMetadata)
WillChangeStatusBarFrame(UIApplication, RectangleF)
Indicates that the frame of the status bar will change shortly.
WillChangeStatusBarOrientation(UIApplication, UIInterfaceOrientation, Double)
Indicates that the orientation of the status bar will change shortly.
WillContinueUserActivity(UIApplication, String) : Boolean
Informs the app that the user is attempting to continue a userActivityType action for which data might not be available, and returns to notify the user that the app will continue the activity.
WillEncodeRestorableState(UIApplication, NSCoder)
Indicates that the app is about to store application state data.
WillEnterForeground(UIApplication)
Called prior to the application returning from a backgrounded state.
WillFinishLaunching(UIApplication, NSDictionary) : Boolean
Indicates that launching has begun, but state restoration has not yet occurred.
WillTerminate(UIApplication)
Called if the application is being terminated due to memory constraints or directly by the user.