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
126
votes
5 answers

How do I prevent the iPhone screen from dimming or turning off while my application is running?

I'm working on an app that requires no user input, but I don't want the iPhone to enter the power saving mode. Is it possible to disable power saving from an app?
lajos
  • 25,525
  • 19
  • 65
  • 75
86
votes
14 answers

iOS Launching Settings -> Restrictions URL Scheme

I've recently discovered the awesome iOS5 custom Settings URL Scheme, which can be explained in detail at this great website. I've found this to work, directing the user to the Settings app from my application: [[UIApplication sharedApplication]…
kturner
  • 1,091
  • 2
  • 10
  • 15
80
votes
10 answers

How to get the name of the running application in iOS

If the application name under the icon on the home screen is "My Awesome App" how do you get that string within the application at runtime?
Jonathan
  • 5,953
  • 1
  • 26
  • 35
62
votes
5 answers

Adding view on StatusBar in iPhone

Is it possible to add a UIView on the staus bar of size (320 x 20)? I don't want to hide the status bar, I only want to add it on top of the status bar.
Biranchi
  • 16,120
  • 23
  • 124
  • 161
60
votes
2 answers

-[UIApplication delegate] must be called from main thread only

This warning leads to a serious problem cause I really can't call the delegate outside of the main thread using Xcode 9 beta 2. Strange thing is that this was working when I was using Xcode 8.3.3. Also I thought it would only be good practice to…
renraku
  • 851
  • 1
  • 9
  • 16
48
votes
5 answers

How to get the actual [UIScreen mainScreen] frame size?

I'm a bit annoyed. I have an app with the statusbar visible in the main window. Since I would like to setup my views and their frame sizes dynamically (perhaps the status bar takes up 40 pixels during a phone call, for example). I can do one of the…
runmad
  • 14,846
  • 9
  • 99
  • 140
45
votes
6 answers

how to get my UIWindow using UIApplication?

I have only one window and I tried UIWindow* mWindow = [[UIApplication sharedApplication] keyWindow]; but this returned nil. I also tried: UIWindow* mWindow = (UIWindow*)[[UIApplication sharedApplication].windows objectAtIndex:0]; But this raised…
user416445
43
votes
2 answers

Getting a reference to the UIApplication delegate

I'm writing my first iPhone application and I'm having trouble switching views. I have 2 views and a reference to each in the AppDelegate (an instance of UIApplicationDelegate). I create instances of both in the applicationDidFinishLaunching and…
derGral
  • 1,836
  • 4
  • 19
  • 29
40
votes
4 answers

What is the difference between UIApplication.sharedApplication.delegate.window and UIApplication.sharedApplication.keyWindow?

Can anyone help me understand the difference between the following two lines: [UIApplication.sharedApplication.delegate.window addSubview:myView]; [UIApplication.sharedApplication.keyWindow addSubview:myView];
tv.ashvin
  • 705
  • 2
  • 7
  • 13
38
votes
8 answers

Get Application's main window

UIApplication has a method keyWindow, however if an alert view is showing then this returns the window of the alert view and not the main window of the application. How can I get the app's main window?
Jonathan.
  • 53,997
  • 54
  • 186
  • 290
35
votes
4 answers

UIApplication sharedApplication - keyWindow is nil?

I want to convert a CGPoint from my UIView to UIWindow coordinates and have realized that UIApplication keyWindow is always nil; why is this? I have tried the convertPoint:toView: method from UIView. Please see this sample code I tried in the view…
nacho4d
  • 43,720
  • 45
  • 157
  • 240
33
votes
4 answers

Accessing the Settings app from your app in iOS 8?

Is it possible to access the settings app from your own app via a button or whatever it may be in iOS 8. I heard that it got decrepitude in iOS 5, is that true? If not did the method change in iOS 8? If there is not other way to do this what would…
Ed3121577
  • 510
  • 1
  • 6
  • 13
32
votes
12 answers

How to get the current application icon in ios

Is there a way to get the current application icon in a cocoa-touch app? Thank you.
the Reverend
  • 12,305
  • 10
  • 66
  • 121
28
votes
5 answers

Open Gmail app from my app

I'm trying to send an email from my app. But what I want is if user is having Gmail app on his/her phone, then mail should be sent using it. If Gmail app is unavailable then the user should be redirected to Mailbox. So how can I know if user…
Ankita Shah
  • 2,178
  • 3
  • 25
  • 42
28
votes
8 answers

Check if my IOS application is updated

I need to check when my app launches if it was being updated, because i need to make a view that only appears when the app is firstly installed to appear again after being updated.
user2412870
  • 295
  • 1
  • 3
  • 7
1
2 3
32 33