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

How to mock property/internal value of UIApplication?

I'm writing unit tests. And I cannot test one function, because it calls keyWindow UIWindow* window = [UIApplication sharedApplication].keyWindow; And keyWindow returns nil (I don't have any window). But I need to return anything, but nil. I used…
artur_i_am
  • 57
  • 5
0
votes
2 answers

Sending email from iPhone with predefined email address

I'd like to make it so the user can send an email address which comes from a predefined email address. So the user does not specify the email address. However, I'd like it so they do define the recipient's email and the content of the email…
Alex
  • 81
  • 2
  • 11
0
votes
3 answers

Can't change app badge in IOS

I am trying to add badge to app icon but simply nothing happens. UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert |…
1110
  • 7,829
  • 55
  • 176
  • 334
0
votes
1 answer

How to stay on our original app when user press cancle button on second app which is opened by custom url scheme IOS?

I am using custom url scheme to open sms,mail and call apps, on call when user press cancel button,caller app dismisses and my app appears on the screen , but in sms and mail app if user press cancel button it is navigating in the same app. it means…
0
votes
1 answer

How to get Application Interface outside of a ViewController?

I have two files .h and .m with some util methods to be called from viewcontrollers. I have one with an alertview, which when the ok button is clicked, the app would terminate. I will use the next code to exit, after user click the…
0
votes
2 answers

Detect Any touch Event across Application in iphone

My objective is to detect any touch event inside My Application on any view... (i.e Inside my application any touch event in anywhere should be detected...) I have tried it by subclassing my appDelegate Class with UIApplication but it is giving me…
Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88
0
votes
1 answer

UIApplication sharedApplication instance is same as given in didFinishLaunchingWithOptions?

Is the instance of UIApplication given in didFinishLaunchingWithOptions is same as [UIApplication sharedApplication]
0
votes
1 answer

Under what circumstances would [ [ UIApplication sharedApplication ] keyWindow ] return nil?

In some cases [[ UIApplication sharedApplication] keyWindow ] returns nil. On some devices it's happening pretty often but in general it's sporadic Anyone know the reasons it would return nil?
dniprodev
  • 1
  • 2
0
votes
1 answer

UIApplicationState of app is inactive after following interactive push notification when app is closed

App is not running. Interactive push notification comes in. User taps a button on it. App is launched, notification action is handled, but app state is still inactive. Even when I background/foreground the app, it's still inactive. If I follow…
Marty
  • 5,926
  • 9
  • 53
  • 91
0
votes
1 answer

How to send action from my app to other app?

I want to send action from my iOS app to other app UIApplication *ourApplication = [UIApplication sharedApplication]; NSString *URLEncodedText = @"..."; NSString *ourPath = [@"...://" stringByAppendingString:URLEncodedText]; NSURL *ourURL = [NSURL…
Ali Rezaei
  • 713
  • 1
  • 5
  • 7
0
votes
1 answer

open application setting page in iOS 6 and 7

In iOS 8 there is now a settings launch URL to send the user directly to the settings page of an App if(&UIApplicationOpenSettingsURLString != nil) { [[UIApplication sharedApplication] openURL:[NSURL…
Vineet Choudhary
  • 7,433
  • 4
  • 45
  • 72
0
votes
1 answer

UIApplication sharedApplication keyWindow - iOS App Widget

I have a simple app and widget for iOS 8. I am making use of the UIImage+ImageEffects source files. One of the functions in that library is called "convertViewToImage" which contains the following code: + (UIImage *)convertViewToImage { UIWindow…
Supertecnoboff
  • 6,406
  • 11
  • 57
  • 98
0
votes
1 answer

How to change [UIApplication sharedApplication].window orientation along with device in iOS

In my application I want to add UIview as a subview on AppDelegate.Window. UIView frame is (0,0,1024,768). After adding view on window it covers only half of the screen. What I understood is view dimensions are screen landscape dimensions. Window…
0
votes
1 answer

Using [UIApplication sharedApplication] to open URL behaving strange

I'm writing an iOS app which is monetized by getting people to sign up to a bookmakers. The bookmaker has offers which change all the time so my idea is to pick out the best offer, and host the link URL on my server. The app will then grab the URL…
James
  • 3,957
  • 4
  • 37
  • 82
0
votes
1 answer

KVO on Local Notifications

I'm updating a button based on if I have local notifications set on my iOS app. I'd like to do this with KVO, as there are various ways notifications can be set so I won't be easily able to track when a change is made to the local notifications…