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
1
vote
1 answer

iOS: UIWindow.rootViewController must be used from main thread only

I have a problem by using if let wd = UIApplication.shared.delegate?.window { var vc = wd!.rootViewController If I put this piece of code in a Dispatch, the warning message disappear, but the application doesn't display…
ΩlostA
  • 2,501
  • 5
  • 27
  • 63
1
vote
1 answer

Top most view controller with multiple window scenes in iOS13

I'm conforming my application to use multiple windows on iPadOS with iOS 13, as far as I know I cannot access to UIApplication window directly due to it's deprecation, how can I get the top most view controller? Until iOS12 I use this working…
Fabiosoft
  • 1,141
  • 14
  • 32
1
vote
0 answers

What is difference between UIApplicationMain and UIApplication

As I know UIApplicationMain will execute as the user will tap on app icon by the system and it will run all loops and app infrastructure. But I don't know when and who calls UIApplication
sham
  • 115
  • 9
1
vote
2 answers

How can I handle a user clicking cancel when prompted to open another app

I have a requirement to open a tweet in my app, if the user has twitter installed, open in Twitter, otherwise present a webview and render the tweet. I am able to achieve this essentially with the below. It works and I am happy with it. However when…
Tim J
  • 1,211
  • 1
  • 14
  • 31
1
vote
1 answer

Delete a UILocalnotification at a certain indexpath

I have a bunch of UILocalNotifications but I only want to delete a certain one at a given indexpath, therefor [[UIApplication sharedApplication] cancelAllLocalNotifications]; wont work out for me. I know I can use [[UIApplication…
user691951
1
vote
1 answer

Is there a way to not open the splash screen/app when launching a shortcut action in iOS?

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { if shortcutItem.type == "com.xyz.test.tests.firstAction" { …
1
vote
0 answers

UIApplication statusBarFrame not up-to-date after didChangeStatusBarFrame

I'm trying to get the updated status bar frame height using didChangeStatusBarFrame, but… The new/updated frame isn't up-to-date and sometimes returns the old and sometimes the new (correct) height. func application(_ application: UIApplication,…
tobi
  • 1,924
  • 2
  • 20
  • 25
1
vote
1 answer

Launching Facebook and Twitter application from other iOS app

Hey guys, I am still continuing to build my iPhone project and I am having trouble with launching the facebook application. First of all, I am assuming every SDK Xcode developer knows that the Facebook application doesn't have the facebook or…
PatrickGamboa
  • 672
  • 4
  • 22
  • 43
1
vote
1 answer

SFSafariviewcontroller - UIApplication sendEvent not working

I am implementing that app timeout functionality, If user keeping the application in idle for five minutes, the application will get logged out automatically. This concept I did use the UIApplication sendEvent method. But, SFSafariviewcontroller…
1
vote
4 answers

How to Remove windows from UIApplication in Swift

While clicking on the button , i am moving to another view controller using the following code. var window: UIWindow? window = UIWindow.init(frame: UIScreen.main.bounds) window?.autoresizesSubviews = true window?.autoresizingMask = [.flexibleWidth,…
Swift_prasad
  • 65
  • 1
  • 11
1
vote
2 answers

How to open url link by using swift?

i want to go to a url by clicking on button. I tried using 'UISharedapplication'and also through the method below mentioned but none works. Please help. Thanks. @IBAction func Displayurl(_ sender: Any) { UIApplication.shared.canOpenURL(NSURL…
jigar dave
  • 39
  • 1
  • 1
  • 11
1
vote
0 answers

iOS Swift - execute func before screenshot is saved

I know how to execute a function after screenshot with: func detectScreenShot(action: @escaping () -> ()) { let mainQueue = OperationQueue.main NotificationCenter.default.addObserver(forName:…
Tom
  • 85
  • 1
  • 1
  • 9
1
vote
2 answers

_UIApplicationHandleEvent deletes data

My situation: I create an object of singleton class. Object has information about Ivars of another object and some NSStrings field. -(id)init { [super init]; objectID=[NSString stringWithString:@"sqlRowId"]; …
Gusev Andrey
  • 446
  • 5
  • 23
1
vote
0 answers

Signal strength in iOS (dbm)?

I am using below mention code to detect the signal strength in the iOS device, This code returns perfect signal strength results in iOS 9 or below version. UIApplication *app = [UIApplication sharedApplication]; NSArray…
Rahul Sharma
  • 940
  • 2
  • 12
  • 31
1
vote
0 answers

App Will Not Be Terminated After backgroundTimeRemaining Reached Zero

I used below code to determine how many time remained to suspending my app. First I called UIApplication.shared.beginBackgroundTask but after backgroundTimeRemainingreached zero my app was not terminated. In another scenario I didn't call…
rick
  • 1,009
  • 2
  • 10
  • 28