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
0
votes
1 answer

Check `[[UIApplication sharedApplication] applicationState]` from background thread, without throwing warning in Xcode 9?

I need to check if the app is in the background and what its backgroundTimeRemaining is, from a non-main-thread. — Apparently this is no longer allowed without throwing the warning. I filed a radar but Apple said this works as intended. So, if…
Ben Guild
  • 4,881
  • 7
  • 34
  • 60
0
votes
1 answer

UIApplication.shared.open with completion handler Swift 4

Looking to open a link via UIApplication.shared.open in Swift4, Xcode9, I'm trying to use a completion block as is standard now, the most common stackoverflow answer is: UIApplication.shared.open(url, options: [:], completionHandler:…
lando2319
  • 1,509
  • 1
  • 19
  • 27
0
votes
2 answers

how to convert UnsafeMutablePointer?> to UnsafeMutablePointer>!

I am using swift 4.0 to re-write main.swift of my iOS application. And this is my main.swift: UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv NSStringFromClass(MyAPP.self), …
archerLj
  • 199
  • 1
  • 2
  • 14
0
votes
1 answer

Selector for a function with multiple parameters

I need my app extension to open my host app with a parameter. I do so by opening a custom URL with UIApplication.shared. Now. My last build has been rejected in test flight with a message "Need test for export compliance" or something like that…
user2578850
0
votes
1 answer

supportedInterfaceOrientationsForWindow seems do not work anymore?

Our app's device orientation is only portrait, but have one video player view which need to rotate to landscape and rotate back; I try to use supportedInterfaceOrientationsForWindow method in AppDelegate, but it seems not work anymore? Xcode 8.3.3,…
tuoxie
  • 81
  • 4
0
votes
1 answer

iOS - How can I create and destroy serial instances of UIApplication?

This may be of little use to anyone, but it's possible to return from UIApplicationMain by nesting the call in a try{}catch(NSException* e){} block. I'm currently doing this for testing my setup process, in order to run some logic after the…
schellsan
  • 2,164
  • 1
  • 22
  • 32
0
votes
1 answer

Objective-c long-running background service for bluetooth, when app backgrounded

I can't seem to find the right documentation, tutorial or SO post to point me towards the right implementation so far... even though there are many posts about this topic floating around. Problem I have an app that connects (pairs) to a BT device I…
GoreDefex
  • 1,461
  • 2
  • 17
  • 41
0
votes
1 answer

How to inherit UIApplication instead of NSObject

I have three Xcode projects and I want to integrate them into one project. Two of those projects are view based application, hence the application delegate has inherited NSObject and UIApplicationDelegate. But the third project is not a view based…
Jayshree
  • 281
  • 1
  • 6
  • 28
0
votes
1 answer

UIApplicationSignificantTimeChange equivalent on Apple Watch

According to the respective documentation, UIApplicationSignificantTimeChange notification is not available on WatchOS. Is there an equivalent notification or way to be notified about significant time changes (new day mainly) on an Apple Watch app?
spassas
  • 4,778
  • 2
  • 31
  • 39
0
votes
1 answer

Refresh application state running on background

I have music player app, and when app goes background it show music control on locked screen, in my case currently playing on radio artist and song. I use following: - (void)applicationWillResignActive:(UIApplication *)application { …
Evgeniy Kleban
  • 6,794
  • 13
  • 54
  • 107
0
votes
2 answers

How to identify whether application is running in background or not

I have an application that ask's password while clicking the application icon(ie. while entering the application). Then i have set UiApplication.getUiApplication().requestBackground(); where application is running in background. Now if am again…
sampath
  • 51
  • 5
0
votes
1 answer

Mock UIApplication open function in iOS 10

I previously mocked the UIApplication in my app this way: How to mock UIApplication in Swift? We now want to get iOS 10 devices to use open(_ url: URL, options: [String : Any] = [:], completionHandler completion: ((Bool) -> Swift.Void)? = nil)…
Hodson
  • 3,438
  • 1
  • 23
  • 51
0
votes
1 answer

Applicationwillterminate and applicatoinwillenterbackground

I have an app that uses background services, so because of this, ApplicationWillTerminate actaully never gets called, intead ApplicationWillEnterBackground gets called when a user TERMINATES not closes an app. The issue is I need to be notified when…
Travis Delly
  • 1,194
  • 2
  • 11
  • 20
0
votes
2 answers

UIApplication has no member keywindow in swift3 Xcode8

I write this code in xcode8 but i have Error : if let window = UIApplication.sharedApplication.keywindow{ let blackView = UIView() blackView.backgroundColor = UIColor.black window.addSubview(blackView) …
0
votes
2 answers

iOS UIApplication windows setEnabled error

With the latest XCode (8.0 (8a218a) release, my app now fails to build with the error message "No known instance method for selector 'setEnabled'" Here is the code, error flagged at the second last line. - if (alertView.tag == PURCHASE_TAG) { …
Rob Slater
  • 225
  • 1
  • 6