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
3
votes
2 answers

How to correctly open URL from UIAlertViewController's handler?

I'm trying to open URL after clicking on alert's button. I've tried different approaches, but none of it worked. Here's my code: let alert = UIAlertController(title: "Warning", message: "Do you want to open the link?", preferredStyle:…
alucarders
  • 31
  • 1
  • 3
3
votes
2 answers

How to share Text on viber , Facebook messenger and Instagram from iOS application?

If any one has idea about how to share text to viber Facebook messenger and instagram than please give some reference. i have try with defultcanOpenURL method for viber and Facebook-messenger as below: Code: NSURL *fbURL = [NSURL…
Pinank Lakhani
  • 1,109
  • 2
  • 11
  • 31
3
votes
0 answers

Understanding the `backgroundRefreshStatus` property

I've an iOS app enabled for updating locations in Background Mode. I'm listening for the UIApplicationBackgroundRefreshStatusDidChangeNotification notification, and checking the backgroundRefreshStatus property. About the property, it is said in the…
AppsDev
  • 12,319
  • 23
  • 93
  • 186
3
votes
2 answers

UIApplication.sharedApplication.scheduledLocalNotifications is always empty

Even if I add a new local notification right before, the attribute is empty. I found a lot of post (and just one on stack overflow) - but nobody has solved this problem. My useless is, that I want to delete a local notification. That's why I want to…
Tobonaut
  • 2,245
  • 2
  • 26
  • 39
3
votes
3 answers

How do I detect touches on UIStatusBar/iPhone

I'm trying to detect any touch on the iPhone's UIStatusBar but its not working. I've tried subclassing UIApplication and UIWindow to access it but still nothing.
timothy5216
  • 280
  • 5
  • 18
3
votes
3 answers

Objective-C iPhone - Open URL in Safari immediately and exit app

I am able to open a URL in Safari using: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.myurl.com"]]; It works fine, but it takes more than 10 seconds in the Simulator. I've tried putting this code inside the app delegate's…
user3724252
  • 31
  • 1
  • 1
  • 2
3
votes
1 answer

openURL:sourceApplication vs didFinishLaunchingWithOptions with UIApplicationLaunchOptionsURLKey

I understand didFinishLaunchingWithOptions returns UIApplicationLaunchOptionsURLKey when launching my app from another application. I also understand that openURL:sourceApplication returns a URL passed when calling my app from another application,…
cohen72
  • 2,830
  • 29
  • 44
3
votes
0 answers

is applicationWillResignActive the earliest indicator we get that an app is becoming inactive?

- (void)applicationWillResignActive:(UIApplication *)application { //pause AVPlayer if music is playing } However upon pressing the Home button the music doesn't actually stop until the iOS has returned to the home screen (after the app-closing…
3
votes
1 answer

Understanding applicationSignificantTimeChange:

I find that sometimes my application (Cocos2d game) beheaves in a "buggy" way after a significant time change. For example: case 1: when the application enters the background and, after several minutes, I restart it, I can see the loading image and…
mm24
  • 9,280
  • 12
  • 75
  • 170
3
votes
2 answers

Setting UIApplication statusBarHidden to YES does not work in iOS 7

I've been using [UIApplication sharedApplication].statusBarHidden = YES; to hide the status bar when users enter specific UIViewControllers in iOS 6 and it worked great. In iOS 7 however it still shows a translucent overlay.
Everus
  • 358
  • 3
  • 17
3
votes
1 answer

Best Practice to handle the extended height status bar with a WantsFullScreenLayout app?

In an app which has the wantsFullScreenLayoutset to YES, what is the best practice to handle an extended height status bar, i.e. with the extra status bar presented when a phone call or a VoIP app is present, or when the personal hotspot feature is…
below
  • 929
  • 6
  • 26
3
votes
1 answer

How to call (dialing) with " * " char in IOS?

I hope to call with * character. ex> *711313. Currently, I'm using this code: NSString *str = [NSString stringWithFormat:@"tel:%@", tmp]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[str…
YoungWoo Lee
  • 73
  • 1
  • 4
3
votes
0 answers

How to mock UIApplication, delegate, window for logic testing on OCUnit?

See the following code, I need to do mock in logic testing, the difficulty is that [UIApplication sharedApplication] always return nil, how do you smart guys resolve this issue? Thank you. UIWindow* root = [UIApplication…
jianhua
  • 1,011
  • 1
  • 12
  • 28
3
votes
1 answer

Adding StatusBar at the bottom of iPhone

I want to show a status bar in the bottom of the iPhone like the one in Gmail account that is appear to indicate that it is checking mail. I have tried the following solution in this thread Adding view on StatusBar in iPhone but the status bar…
Mahmoud Adam
  • 5,772
  • 5
  • 41
  • 62
2
votes
1 answer

How send application to background when install on device?

I am making an application in which i want features like as when i run my app on device then it will closed immediately without showing any screen.But Application works in background. When user click on icon of application then it will not show any…
ios
  • 552
  • 5
  • 22