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

How do you deal with singleton objects in your app?

The first approach that comes to my mind is to put the singleton object in the appDelegate object as property. In this way you can access it from anywhere using #import "myAppDelegate.h" // ... [[(myAppDelegate *)[UIApplication sharedApplication]…
gurghet
  • 7,591
  • 4
  • 36
  • 63
1
vote
0 answers

What state is a Cocoa app in when application(_:continueUserActivity:restorationHandler:) is called?

I'm going through hell trying to understand state in iOS apps :-( I'm implementing Universal Links and the basics are working. However, I'm confused about the state of the app when this method is called in the AppDelegate: func…
andy
  • 8,775
  • 13
  • 77
  • 122
1
vote
3 answers

How UIApplication knows when a UIWindow is created in the app?

In the UIApplicationDelegate's application:didFinishLaunchingWithOptions: I have the following code: NSLog(@"%d\n", [UIApplication sharedApplication].windows.count); self.mainWindow = [[UIWindow alloc]initWithFrame:[UIScreen…
Viktor Simkó
  • 2,607
  • 16
  • 22
1
vote
0 answers

"This app is not allowed to query for scheme googlechrome"

I am getting this error -canOpenURL: failed for URL: ”googlechrome:“ - error: ”This app is not allowed to query for scheme googlechrome" I tried adding to the .plist but it made no difference: LSApplicationQueriesSchemes
Kada
  • 63
  • 8
1
vote
2 answers

Opening another (mine) application from my main application Swift

I have two applications and i want to open them from each other (like facebook opens messenger). After a little search i found that i have to know the url scheme of my app, but i don't know how can i declare it. In my urlSchemes are only facebook's…
mike vorisis
  • 2,786
  • 6
  • 40
  • 74
1
vote
2 answers

Cannot Pause Game when app is in the Background State

This may be a really basic question, but I have made a simple game in which the user avoids oncoming obstacles. When I press the home button my app is still running in the background, and because of this the app music continues playing and all my…
1QuickQuestion
  • 729
  • 2
  • 9
  • 25
1
vote
0 answers

statusBarOrientation in iOS extension

I'm having some trouble with my iOS extension. My library uses [[UIApplication sharedApplication] statusBarOrientation] to detect the orientation. sharedApplication isn't available in an iOS extension, so I thought I'd use a macro. It keeps throwing…
user4992124
  • 1,574
  • 1
  • 17
  • 35
1
vote
1 answer

activityIndicators and UIApplication.sharedApplication()

Calling unlock device is not working it prints "unlockCalled" a lot of times and then gives this error: 2016-03-27 14:20:45.976 xxx[1002:57886] -[UIApplication endIgnoringInteractionEvents] called without matching -beginIgnoringInteractionEvents.…
1
vote
2 answers

objective C Basic question

i made a simple application using view based template.and i put only nslog inside view didload method in viewController file and also inside applicationDidFinishLaunch method (in appDelegate )to checked which class file called first. after the…
1
vote
3 answers

Is it possible to subclass UiApplicationDelegate protocol?

To be honest I don't know how to call it, so I'll try to describe it. UIApplicationDelegate protocol has "application:handleOpenURL:" method. And if I implement this method in my ApplicationDelegate class, it will be called when somebody opens my…
1
vote
2 answers

Swift: Shut down app after countdown

I created a 4:00 minute countdown timer with an acoustic signal when it reaches 0:00. I used a function that prevents the phone from falling asleep while the timer is running. However, this is the last screen of my app. So once the acoustig final…
mojomo
  • 109
  • 11
1
vote
2 answers

Not able to launch native Facebook app

I´m trying to launch a Facebook page, first I check if it can be opened in the native app and then open in Safari if not. I do have Facebook installed, but it always open the page in Safari. This is the code I´m using. let fbId = "ID" // this is of…
user5700760
1
vote
0 answers

Dynamically changing the text on an UIApplicationShortcutItem

I implemented two dynamic "Home screen quick actions" as UIApplicationShortcutItem in my rootViewController- just like Apple suggests in their documentation. This works like a charm. My problem is, I would like to change the text of my titles and…
Anfaje
  • 335
  • 4
  • 14
1
vote
2 answers

Simulator not displaying UILocalNotification

I am trying to incorporate localnotifications that fire after a certain time interval, however, I can't seem to get the notification to display at any point when testing with the simulator. I simply want to display the local notification 10 seconds…
1
vote
1 answer

Why can't I do this in app delegate?

UIWindow *second = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; NSMutableArray *wArray = [NSMutableArray arrayWithArray:[UIApplication sharedApplication].windows]; [wArray addObject:second]; [[UIApplication sharedApplication]…
Y Robin
  • 80
  • 1
  • 6