How to launch any arbitrary iPhone application from within another app?


iOS Allows us to open some applications with some links or other ways from our app, like dialing a number when clicked on it, or writing a mail with some static body or writing a SMS. But this is limited to some applications, not every app can be opened from within an application.

Specifically it is limited to apps that have a registered URL Scheme. For example if you want to open a SMS from your app, it is possible using the registered URL Scheme.

Some of the applications that can be opened with URL schemes and how to open them are mentioned below.

Opening Phone Dialer with iOS

To call a number from our application we have to use URL scheme tel:// followed by the mobile number to call, when this action is performed it opens up the dialer.

We have to create a url to open dialer,

URL(string: "tel://\(number)"), UIApplication.shared.canOpenURL(url)

One example of a function to dial a number is −

func callNumber(number: String) {
   if let url = URL(string: "tel://\(number)"),
   UIApplication.shared.canOpenURL(url) {
      if #available(iOS 10, *) {
         UIApplication.shared.open(url)
      } else {
         UIApplication.shared.openURL(url)
      }
   }
}

Similar to this, URL Scheme example to open some other apps are −

Whatsapp

UIApplication.shared.openURL(URL(string:"https://api.whatsapp.com/send?ph
one=\(mobile_number)")!)
Contacts - contacts://
iBooks – ibooks://
itunes - itms-itunesu://
photos - photos-redirect://
safari - x-web-search://
facebook - fb://
google Chrome - googlechrome://
messenger - fb-messenger://
skype - skype://
twitter – twitter://

Updated on: 27-Jun-2020

677 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements