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
1
vote
3 answers

openURL not opening safari to from app

I have to clarify that I know how to open url from our iOS app, like [[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlAddress]]; In my code I have done the same. It is an old app and I have to upgrade this app right now. I'm…
Max
  • 2,269
  • 4
  • 24
  • 49
1
vote
2 answers

Unit testing UILocalNotification

I am writing a framework that wraps UILocalNotifiations, and in the processes of writing unit tests for it. It's actually more of a functional test, but whatever. So, the test I am trying to write is: func…
Mazyod
  • 22,319
  • 10
  • 92
  • 157
1
vote
1 answer

Prevent dimming screen in iOS App Extension

I'm developing an iOs app with an Action App Extension. While the Action App Extension is running, I want to prevent the device from dimming its screen. I've added [[UIApplication sharedApplication] setIdleTimerDisabled:YES] but its giving me this…
1
vote
0 answers

Tab bar image not working

I need your help here. My app has 5 tab bars. The first tab bar's image will be missing after make a phone call using openURL. And this is only happen when running the app in iOS 8/9. Below is the coding where I make a phone…
Kit
  • 11
  • 1
1
vote
2 answers

applicationDidEnterBackground and applicationWillTerminate both called when user swipes up to quit app

I am adding some notifications for when the user sends the application to the background or when they completely quit the app. However when they quit the app, both the methods applicationDidEnterBackground and applicationWillTerminate are called.…
1
vote
2 answers

System ignore iPhone rotation

Is there a function like beginIgnoringInteractionEvents in UIApplication that ignores rotation instead of touches? I need my app NOT to rotate just in an MPMovePlayerViewController that I present. Thanks [UPDATE] Here's my code --…
jmont
  • 423
  • 3
  • 12
1
vote
3 answers

UIApplication openURL vs NSURLConnection initWithRequest for launching iTunes

I want to launch iTunes via my app. Currently there's a code that's doing that using [NSURLConnection alloc] initWithRequest. I'm thinking about changing it to [UIApplication sharedApplication] openURL. What is the difference and what is the correct…
YogevSitton
  • 10,068
  • 11
  • 62
  • 95
1
vote
1 answer

iPhone SDK - On Device Locked or On Device Unlocked and application shown

I need to find a way to detect when a device has been locked, or else a way to detect when the device has been unlocked, and sent straight to the app where it left off. Is there some method like: -…
Hank Brekke
  • 2,024
  • 2
  • 24
  • 33
1
vote
1 answer

The proper way to enable landscape orientation only for some devices in iOS 8.3

I'm developing an Universal App in iOS SDK 8.3 and I'm using UISplitViewController. For some reasons I want to enable landscape orientation only for iPads and iPhone 6 Plus. I can't find out a proper way to obtain this and for the moment I'm using…
1
vote
3 answers

How to present Lock_ViewController when app is entering foreground in SWIFT?

Please help me. I have an app that has a passcode lock feature, this gets activated everytime the user opens the app. If the user goes to home ( app goes to background) and then go back to the app ( foreground) I want to display the lock screen…
1
vote
0 answers

UIApplication sharedApplication EXC BAD ACCESS in a UITextField category

- (void)someMethod { BOOL isRightToLeft = ([UIApplication sharedApplication].userInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft) } This causes exc bad access. I'm thinking its because its not thread safe and its called many…
Ted
  • 22,696
  • 11
  • 95
  • 109
1
vote
3 answers

Cannot use [UIApplication sharedApplication]. How can I register for notifications outside UIApplicationDelegate?

I'm writing an application with a WatchKit extension. I used to be able to register for notifications outside UIApplicationDelegate using [[UIApplication sharedApplication] registerForNotificationTypes:]. [UIApplication sharedApplication] is now…
1
vote
0 answers

Conditionally set keyWindow rootViewController from storyboard instantiate not working in iOS7

I have a login for my app, so I need to conditionally set the keyWindow rootViewController based on if they have saved authentication. If there is authentication, show the tabBarController, if there isn't, show the login view. In my Storyboard I…
Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412
1
vote
2 answers

App crashes on startup, only on my computer

I have Xcode 6.1.1, and my app crashes on start up. It never reaches the start view (not even its awakeFromNib), but crashes on UIApplication on main. When it breaks there, I get NOTHING in the debug. Literally nothing. If I continue the program…
ClockWise
  • 1,509
  • 15
  • 32
1
vote
2 answers

asking for notification permission swift (iOs 7)

How I can ask for permissions in iOs 8 and iOs7 both. I've tried this: UIApplication.sharedApplication().registerForRemoteNotificationTypes(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) But it doesn't…
user2084676