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
1 answer

How implement scheduling event with post a message on fb

I am creating an application in which I have add a facility for post message on ur account. Now this facility I am adding an event for scheduling. With help of that user can write a message and post that later or on particular date and time. For…
1
vote
2 answers

UIApplication kind of quits while in background

When you open up an app and press home screen again, the app is obviously in te background. When you open other apps and wait a time, the views of my app have been unloaded (like UITableView reloads data). Is there some sort of notification or how…
lbrndnr
  • 3,361
  • 2
  • 24
  • 34
1
vote
0 answers

How can I jump to Photos app by a specific image's identifier on my App?

This question is similar to how can I show selected image in the Photos app. I'm writing a photo gallery app that loads photos from Photos using PHImageManager.requestImage(), so for a specific low-quality image(usually CGSize(width: 256, height:…
MazzzyStar
  • 45
  • 8
1
vote
0 answers

How would one open an iMessage app extension from the hosting application?

I'm trying to open an iMessage extension application from the main hosting extension using URL in the following manner, if UIApplication.shared.canOpenURL(url){ UIApplication.shared.open(url) }else{ print("unable to open URL") } I added the url…
1
vote
1 answer

Swift: Unable to make UIApplication conform to my protocol

I'm trying to make UIApplication conform to the following protocol: protocol URLOpenerProtocol { func open(_ url: URL, completionHandler: ((Bool) -> Void)?) } I've added the following extension: extension UIApplication: URLOpenerProtocol…
DevB1
  • 1,235
  • 3
  • 17
  • 43
1
vote
1 answer

Can an iOS App Switch to Safari Without Opening a Page?

I know that my app can open a particular URL in Safari by doing something like this: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.example.com/"]]; but, is there any way to have my app switch over to Safari without…
Kristopher Johnson
  • 81,409
  • 55
  • 245
  • 302
1
vote
0 answers

Why UIApplication.shared.canOpenURL(url) woks on one device and doesn't on another

I have a well-known part of code to open another app from my app. And mainly it works as expected. But there is a group of users where I see an error log that shows that it doesn't work. So, shortly, there are two iPhones and one can open URL and…
1
vote
1 answer

How to access UIApplication subclass functions

I have VC1 that is subclass of UIApplication VC1 class CustomUIApplication: UIApplication { override func sendEvent(_ event: UIEvent) { super.sendEvent(event) } func stopTimer() { …
tp2376
  • 690
  • 1
  • 7
  • 23
1
vote
1 answer

a question about the sendEvent method of UIApplication

I override the - (void)sendEvent:(UIEvent *)event method of UIApplication to handle some touch event. .h @interface myUIApplication : UIApplication { } .m @implementation myUIApplication - (void)sendEvent:(UIEvent *)event { NSLog(@"a event…
Solskjaer
  • 175
  • 1
  • 11
1
vote
1 answer

Migrating old Xcode project to new one with UISceneDelegate

I have an old Xcode project without UISceneDelegate methods. Is it possible to migrate an old Xcode project to a new one with UISceneDelegate methods BUT still maintaining compatibility with iOS 12? If so, how? Because I see a lot of bugs in iOS 14…
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
1
vote
1 answer

Open mail screen in own app instead of mail app

I'm using the newest Xcode and Swift version. I'm using the following code to initiate a screen to write an e-mail: UIApplication.shared.open(URL(string: "mailto:test@example.com")!) This code opens the Apple mail app, creates a new e-mail and…
David
  • 2,898
  • 3
  • 21
  • 57
1
vote
1 answer

Sending email with html tag via [UIApplication sharedApplication] on iPhone

I am trying to send an email with an embed code (html snippet) but the email body is empty. NSURL *url = [NSURL URLWithString: me.emailUrl]; [[UIApplication sharedApplication] openURL:url]; …
loopmasta
  • 1,693
  • 3
  • 14
  • 19
1
vote
1 answer

Hide UiApplication Icon on a BlackBerry?

I am creating a tracking application. Once configured, the application should always run in the background, without the knowledge of user. There is option to hide the application icon manually by selecting the app and pressing the BlackBerry icon…
Nadhas
  • 5,421
  • 2
  • 28
  • 42
1
vote
1 answer

UIApplicationMain class function inside ViewController

I have a functionality throughout my application. Now i need to call a specific function inside one view controller for some particular condition. So i tried to call, but it fails main.swift CommandLine.unsafeArgv.withMemoryRebound(to:…
1
vote
1 answer

How to programmatically hide and show status bar in iOS 13?

I have made following common method for hiding and showing again status bar. It works fine before iOS 13, but I am getting following crash while I run it for device having iOS 13 or greater. +(void)showStatusBar:(BOOL)show { UIView *statusBar =…
NSPratik
  • 4,714
  • 7
  • 51
  • 81