Questions tagged [uiapplication]

The UIApplication class provides a centralized point of control and coordination for apps running on iOS. Every app must have exactly one instance of UIApplication (or a subclass of UIApplication). When an app is launched, the UIApplicationMain function is called; among its other tasks, this function creates a singleton UIApplication object. Thereafter you access this object by invoking the sharedApplication class method.

The UIApplication class provides a centralized point of control and coordination for apps running on iOS. Every app must have exactly one instance of UIApplication (or a subclass of UIApplication). When an app is launched, the UIApplicationMain function is called; among its other tasks, this function creates a singleton UIApplication object. Thereafter you access this object by invoking the sharedApplication class method.

A major role of a UIApplication object is to handle the initial routing of incoming user events. It also dispatches action messages forwarded to it by control objects (UIControl) to the appropriate target objects. In addition, the UIApplication object maintains a list of all the windows (UIWindow objects) currently open in the app, so through those it can retrieve any of the app’s UIView objects. The app object is typically assigned a delegate, an object that the app informs of significant runtime events—for example, app launch, low-memory warnings, and app termination—giving it an opportunity to respond appropriately.

Apps can cooperatively handle a resource such as an email or an image file through the openURL: method. For example, an app opening an email URL with this method may cause the mail client to launch and display the message.

The programmatic interfaces of UIApplication allow you to manage behavior that is specific to the device. Use this object to do the following:

  • Control the app’s response to changes in interface orientation.

  • Temporarily suspend incoming touch events.

  • Turn proximity sensing (of the user’s face) off and on again.

  • Register for remote notifications.

  • Trigger the undo-redo UI (applicationSupportsShakeToEdit).

  • Determine whether an installed app can open a URL (canOpenURL:).

  • Extend the execution of the app so that it can finish a task in the background.

  • Schedule and cancel local notifications.

  • Coordinate the reception of remote-control events.

  • Perform app-level state restoration tasks.

UIApplication defines a delegate that must adopt the UIApplicationDelegate protocol and implement some of the protocol methods.

Subclassing Notes

Most apps should never need to subclass the UIApplication class. Most apps use an app delegate to manage interactions between the system and the app.

The only situation where you might need to subclass UIApplication is when you are implementing a custom event or action dispatching mechanism. In that situation, you might override the sendEvent: or sendAction:to:from:forEvent: methods to implement that mechanism. However, the cases where this is required are very rare and should be avoided whenever possible.

484 questions
26
votes
7 answers

canOpenURL failing for system-wide URL schemes

I'm running iOS 9b5. In my app, if a device can make a phone call, I want to color the text blue so it looks tappable. If not, I leave it black. In order to determine the device capabilities, I use: [[UIApplcation sharedApplication]…
djibouti33
  • 12,102
  • 9
  • 83
  • 116
25
votes
5 answers

What is the relationship between AppDelegate, RootViewController, and UIApplication?

I am trying to figure out the relationship between the appdelegate, RootViewControoler, and UIApplication. Here is what I kinda have figured out so far: When starting your application up, main.m gets loaded. From here, your MainWindow.xib gets…
guy8214
  • 1,115
  • 2
  • 12
  • 14
19
votes
3 answers

Need clarification about UIApplicationState

I need your help in clarifying my understanding of the various states of an app. I am going to state my interpretation - but please feel free to correct me. 1) App is launched and running in the foreground: state = UIApplicationStateActive 2)…
Sam
  • 827
  • 4
  • 9
  • 21
19
votes
9 answers

Swift. URL returning nil

I am trying to open a website in my app, but for some reason one line keeps returning nil, heres my code: let url = URL(string: "http://en.wikipedia.org/wiki/\(element.Name)")! if #available(iOS 10.0, *) { UIApplication.shared.open(url,…
Benja0906
  • 1,437
  • 2
  • 15
  • 25
18
votes
2 answers

UIApplication openUrl not working with formatted NSString

I have the following code to open google maps: NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@, Anchorage, AK",addressString]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; But it…
agentfll
  • 858
  • 2
  • 10
  • 21
17
votes
2 answers

openURL from App Extension

On iOS 8 beta 2 it should be possible to use openUrl from app extension as written into the release notes: however when I try to use this API (on Xcode 6 beta 2) I get the following error: Beta 2 really fixed this issue or not?
Massimo Piazza
  • 663
  • 3
  • 7
  • 21
16
votes
2 answers

What describes the Application Delegate best? How does it fit into the whole concept?

I think to know what the App Delegate does. It has some nice methods like -applicationDidFinishLaunching which will be called when the app has finished launching, and so on. But what's that actually? Is that some object instantiated in the…
Thanks
  • 40,109
  • 71
  • 208
  • 322
16
votes
1 answer

UIApplication's -canOpenURL: -openURL: return misleading result

Since iOS6, I can't tell whether the application can launch Safari or not. If Safari is restricted on the device (Settings>General>Restrictions), nothing happens when trying to open a URL, and there's no indication of what went wrong: NSURL *url =…
hwaxxer
  • 3,363
  • 1
  • 22
  • 39
14
votes
1 answer

How does Booking.com close their app programmatically?

I just saw this trick the Booking.com app does to let you change the application's language: I'm not aware of any technique to programmatically close an iOS app (and it's also forbidden by Apple's guidelines, but let's "pretend" that my boss wants…
Tamás Zahola
  • 9,271
  • 4
  • 34
  • 46
14
votes
5 answers

How to launch the iOS mail app in Swift?

I'm creating an iOS application with a password reset feature that sends an email to the user. After sending the email I want to display a UIAlertController to the user asking them if they would like to open the mail application. I've seen various…
Kyle Decot
  • 20,715
  • 39
  • 142
  • 263
13
votes
2 answers

How can I use universal links when I call openURL inside my own app?

My app uses in different screens: [[UIApplication sharedApplication] openURL:url]; in order to open URLs received from my web service. Sometimes, those URLs are unrelated to my project, so opening them going to Safari is OK. Others, those URLs…
Ricardo
  • 2,831
  • 4
  • 29
  • 42
13
votes
2 answers

Is this possible to apply the alternative icon to the iOS application?

I need to change the app icon based on region, is this possible?
Mohamed Raffi
  • 1,165
  • 1
  • 7
  • 15
13
votes
1 answer

How did Vesper show users wallpaper without UIApplicationIsOpaque key?

An app named Vesper was updated for iOS 7 and shows the user's wallpaper on iOS 7. I have found that using UIApplicationIsOpaque key and UIBackgroundStyleLightBlur can show the users background but will not pass validation. Vesper passed validation…
Maximilian Litteral
  • 3,059
  • 2
  • 31
  • 41
13
votes
6 answers

Dismiss an already delivered UILocalNotification?

Is it possible to do this? UIApplication's scheduledLocalNotifications doesn't seem to return notifications that have already been delivered to the user's notification center, so I think this may be by design, but I can't find any documented…
elsurudo
  • 3,579
  • 2
  • 31
  • 48
12
votes
1 answer

UIApplication.delegate must be used from main thread only

I have the following code in my app delegate as a shortcut for working with CoreData in my other viewControllers: let ad = UIApplication.shared.delegate as! AppDelegate let context = ad.persistentContainer.viewContext However, I now get the error…
LFHS
  • 295
  • 1
  • 2
  • 15
1
2
3
32 33