How to Launch Safari from an iPhone App

Open iOS app from browser

You can achieve what you're asking for by using a URL scheme. This will enable you to call the openUrl: method with your application's url scheme which will then launch your app.
Here's how you setup a custom url scheme:

  1. Open your app's Info.plist and add a row with a key called URL Types.
  2. Expand the URL Types item, and Item 0 under it and you'll see URL Identifier
  3. Enter your app's bundle identifier (e.g. com.myCompany.myApp) as the URL Identifier value.
  4. Add another row to Item 0 and enter URL Schemes.
  5. Expand the URL Schemes and under Item 0 type in the name for your custom scheme (e.g. myScheme).

You should now be able to open your app from Safari by typing myScheme:// in the address bar.
Alternatively, from your app, you can launch the other app like this:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"myScheme://"]];

Note that you can also send parameters to the app you're launching with the url scheme (more on that here).

Launching Safari App without using any specific url from an iOS App

Actually we can open a specific app from safari. You have to create a custom url scheme for the application and open that link from safari like any other link is opened from safari.

Create a custom url scheme like

myApp://

Then open it from safari e.g on onClick of button.

Automate launching Safari from a iOS mobile app using appium

it doesn't allow you to sent commands to more than one app per session

Thats true, but you can run 2 sessions in a single test:

  1. create instance of appium driver with app-based capabilities
  2. do what you need in the app
  3. quit driver
  4. create instance of appium driver with browser-based capabilities
  5. do what you need in the safari
  6. quit driver

In a quick way it may look like:

@Test
public void testBothAppAndSafari() throws MalformedURLException {
URL appiumServerUrl = new URL("");
DesiredCapabilities appCaps = new DesiredCapabilities();
// put required native app capabilities in appCaps
DesiredCapabilities safariCaps = new DesiredCapabilities();
// put required safari capabilities in safariCaps

IOSDriver driver = new IOSDriver(appiumServerUrl, appCaps);
driver.findElement().click();
// do whatever you want with mobile app
driver.quit();

driver = new IOSDriver(appiumServerUrl, safariCaps);
driver.findElement().click();
// do whatever you want in safari
driver.quit();
}

Open Safari iOS App from Watch App

This is only possible if the iOS app happens to be running in the foreground. If you use the WatchConnectivity sendMessage API to wake the iOS app up in the background then you won't be able to open URLs and therefore not launch Safari.

How to open Safari from a WebApp in iOS 7

Having an anchor tag with target _blankwill work in iOS 7.0.3 but using window.open will not work and will remain to open within the webview in 7.0.3:

window.open('http://www.google.com/', '_blank');


Related Topics



Leave a reply



Submit