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

UIApplication sharedapplication openURL not working

I have this method - (IBAction)facebookButtonPress:(id)sender { NSLog(@"fb hit"); [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"www.facebook.com/asbreckenridge"…
AndrewSB
  • 951
  • 3
  • 11
  • 25
12
votes
4 answers

How can I remove UIApplicationMain from an iPhone application?

I'm trying to port a game library over to the iPhone. Unlike SDL, this library doesn't take full control of your main() function, it's communicated with via quickly-returning functions from your own code. So, for example, obvious pseudocode: int…
ZorbaTHut
  • 1,163
  • 1
  • 11
  • 19
12
votes
3 answers

Differentiate between screen lock and home button press on iOS7

I need to do something in applicationDidEnterBackground. But I need to differentiate which user action causes the "enter background": screen lock or home button press. I was using this code, which is from this post - How to differentiate between…
Perisheroy
  • 239
  • 4
  • 8
12
votes
3 answers

Confusion between background vs suspended app states

I am bit confused about these two states. Following is my understanding; when app is in background and if you have "Application does not run in background" set to NO in App plist file then App continues running in background. In suspend mode…
Paresh Masani
  • 7,474
  • 12
  • 73
  • 139
11
votes
3 answers

What is Objective C execution order after UIApplicationMain in Main?

Could someone please explain how control of execution flows in an iOS application? I know that UIApplicationMain is called first from main. Then what? What is the relationship between my defined methods and main? Is it all event-driven or can there…
Old McStopher
  • 6,295
  • 10
  • 60
  • 89
11
votes
2 answers

iOS: idleTimerDisabled = YES works only until ImagePicker was used

I have an iPad survey tool as an internal enterprise application. I prevent screen locking with setting [[UIApplication sharedApplication] setIdleTimerDisabled: YES]; at didFinishLaunchingWithOptions of the application delegate. That works fine…
Marcus Franzen
  • 868
  • 10
  • 25
11
votes
6 answers

How can I find out whether the user pressed the Call or the Cancel button when making a call from my app?

I need to return to my app after making a call from my app, so I use this code: NSURL *url = [NSURL URLWithString:@"telprompt://123-4567-890"]; [[UIApplication sharedApplication] openURL:url]; When the user presses a button to execute this code,…
DixieFlatline
  • 7,895
  • 24
  • 95
  • 147
11
votes
1 answer

How to re-enable the idle timer in ios once it has been disabled (to allow the display to sleep again)?

I have figured out how to stop an iOS device from going to sleep (see below), but I am having troubles undoing that setting. According to the Apple Documentation, it should just be changing the value of the idleTimerDisabled property. But when I…
lindon fox
  • 3,298
  • 3
  • 33
  • 59
10
votes
3 answers

Finding the rootViewController in iOS

In ShareKit, the code needs to determine where the rootViewController is so it can show a modal view. For some reason, the code is failing in iOS 5: // Try to find the root view controller programmically // Find the top window (that is not…
Jim
  • 5,940
  • 9
  • 44
  • 91
10
votes
2 answers

Accessing `shared` variable of `UIApplication` from inside `share extension` in Swift

I need to execute my host app from inside an extension. In Objective-C I've used this: // Get "UIApplication" class name through ASCII Character codes. NSString *className = [[NSString alloc] initWithData:[NSData dataWithBytes:(unsigned char…
user2578850
10
votes
2 answers

Calling openURL to install App OTA results in installing a cached app

I'm creating an in-house app to deliver updated apps that our business clients can install wirelessly. Ultimately the way I'm launching the install is: NSURL *otaURL = [NSURL…
Trey
  • 101
  • 1
  • 5
9
votes
2 answers

UIApplication icon badge number remains at re-install

The UIApplication badge number is not deleted at reinstall. In case I uninstall the application when the badge has a non zero value, and then re-install it, the badge still appears in the new installation. I update the badge number in the following…
yaara4
  • 304
  • 3
  • 8
9
votes
2 answers

UIApplicationDidEnterBackgroundNotification

whats the use of UIApplicationDidEnterBackgroundNotification in iPhone app or how we can take benifit from it
Manish Jain
  • 865
  • 3
  • 13
  • 28
9
votes
1 answer

Proper use of UIApplicationMain

I have decided to load my views programmatically, so putting: int ret = UIApplicationMain(argc, argv, nil, nil); Would not work. I do have a ViewController and an AppDelegate, though. What would be the proper use of UIApplicationMain to use a…
Mohit Deshpande
  • 53,877
  • 76
  • 193
  • 251
9
votes
0 answers

Sharing video to instagram with UIDocumentInteractionController

How do you share an .mp4 video file to Instagram? I can share images like this: NSString* filename = [NSString stringWithFormat:@"testImage.igo"]; NSString* savePath = [imagesPath stringByAppendingPathComponent:filename]; …
soleil
  • 12,133
  • 33
  • 112
  • 183
1 2
3
32 33