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

Swift - Shake gesture dismisses the child view controller

I have two view controllers which are defined in storyboard as, UIViewController -> (Show Detail Segue) -> UITabBarController My problem is; I am using a library called netfox to debug my HTTP requests. And this librarie's UI is being triggered by…
Faruk
  • 2,269
  • 31
  • 42
2
votes
1 answer

UIApplication not opening url

I am grabbing the URL from a struct and sending it to a UITapGesture, and I tried printing it(it prints URL), but it doesn't want to actually open the URL. @objc func getUrl(sender: UITapGestureRecognizer){ guard let url = self.rssUrl else {…
user9394260
2
votes
2 answers

Where to implement applicationWillResignActive(_:)?

In order for the ViewController to "do something specific" just before the app goes into the background state... I am to understand that this sort of thing is generally handled inside the applicationWillResignActive(_:) method, but this method…
Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100
2
votes
0 answers

How can I get the original status bar height without in-call addition?

If I read [[UIApplication sharedApplication] statusBarFrame].size.height, then I get height of the frame of the status bar with in-call addition (press Command+Y in the Simulator to see it). But how can I get the original status bar height without…
Dmitry
  • 14,306
  • 23
  • 105
  • 189
2
votes
1 answer

App screen snapshot being shown instead of launchScreen during state restoration

I encountered this situation where I had added app state restoration APIs for the first time to a new app supporting iOS 9.3 and higher. The state restoration is working fine functionally, but I noticed that it was showing a screen snapshot…
drshock
  • 2,096
  • 2
  • 15
  • 30
2
votes
0 answers

When to use UIApplication.keywindow and UIApplicationDelegate.window?

I'm working on a somewhat new project (with Swift) and I just realized UIApplication.keywindow and UIApplicationDelegate.window are being used (apparently) like they are the same. From this question I understand the are in fact NOT the same; but…
Andres C
  • 463
  • 6
  • 26
2
votes
1 answer

Swift AppDelegate application:didFinishLaunchingWithOptions error

Here is my code: func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { return true } I am reading through tutorials for local push notifications for my iOS app and this…
AtomProgrammer
  • 327
  • 2
  • 13
2
votes
0 answers

UIApplication wil not remove window from windows immediately

I want to create a float window above the main window, so code like blow. I use a fake singleton pattern to manage a UIWindow. Because I don't want other object retain the window. The code: @class testWindow; static testWindow *singletonSelf; static…
S.Captain
  • 167
  • 1
  • 9
2
votes
0 answers

Could not cast value of type 'UIApplication' to AutoLogoutUIApplication

When I cast UIApplication.shareApplication() to my custom class AutoLogoutUIApplication, I got an error like below when I use Swift. Could not cast value of type 'UIApplication' (0x28f4408) to 'Porject_Name.AutoLogOutUIApplication'…
vichhai
  • 2,548
  • 2
  • 15
  • 25
2
votes
1 answer

How to know if user is interacting with app

I need to perform some Heavy UI task.Before starting that task , I want to check if user is interacting with app , like scrolling the table or entering input in textfield. Is there any way to check it ?
2
votes
1 answer

Add UIView with UIButton onto UIWindow with click

I am wanting to add a UIView above my entire app. This part is easy: UIView* myView = /* Your custom view */; UIWindow* currentWindow = [UIApplication sharedApplication].keyWindow; [currentWindow addSubview:myView]; My UIView has a UIButton as a…
Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412
2
votes
2 answers

Swift observe UIApplication property

Is it possible to somehow observe property of UIApplication.sharedApplication() in swift? I need to track UIApplication.sharedApplication().applicationIconBadgeNumber to update my app UI based on that number, but whenever this property is changed UI…
zhuber
  • 5,364
  • 3
  • 30
  • 63
2
votes
2 answers

How do I change the UIWindow window.tintColor back to default after changing it?

I'm doing the following code to make a system-wide theme change to my app for button colors: UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject]; window.tintColor = [UIColor themeColorNamed:@"barAndButtonTextColor"]; The…
Ethan Allen
  • 14,425
  • 24
  • 101
  • 194
2
votes
1 answer

Core Spotlight, continueUserActivity in objective-c?

iOS 9.2, xCode 7.2, Objective-C I used this tutorial (Core Spotlight version) but translated it into Objective-C: http://code.tutsplus.com/tutorials/ios-9-introducing-search-apis--cms-24375 Everything works except one thing - I can't get callback…
2
votes
1 answer

XCTest: [UIApplication sharedApplication] is returning nil

I have written a framework with all the utility(Common) functions in Objective-C. Since it is a framework, it does not have an App delegate file. I have created an UIApplication class and have few utility methods in it. @interface TestApplication :…
Coder
  • 1,661
  • 4
  • 27
  • 50