How to Programmatically Check and Open an Existing App in iOS 8

How to check programmatically if an App is installed?

I think this is not possible directly, but if the apps register uri schemes you could test for that.

A URI scheme is for example fb:// for the facebook app. You can register that in the info.plist of your app. [UIApplication canOpenURL:url] will tell you if a certain url will or will not open. So testing if fb:// will open, will indicate that there is an app installed which registered fb:// - which is a good hint for the facebook app.

// check whether facebook is (likely to be) installed or not
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
// Safe to launch the facebook app
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/200538917420"]];
}

How to open Documents files of device programmatically in iOS

To open office files within an iOS app you can:

1- Use UIWebView . Here is a sample code with a document included in the app's resources.

NSString *path = [[NSBundle mainBundle] pathForResource:@"document" ofType:@"ppt"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];

2- You can use the QuickLook framework to preview the files "in app".

Reference

Tutorial with sample code

3- You can use the document interaction controller to open the files using available apps that can handle them in the device.

tutorial

4- Avoid downloading and storing files without getting user permission, or at least informing users. You can even put this in your "terms and conditions". Also, be sure not to include those downloaded URL in iClowd backups.

How to programmatically open Apple Watch companion app from iOS app

I guess it's not possible to programmatically launch the watch companion app from iOS. The opposite way would be possible: to launch the iOS app in the background upon receiving a message from the watch. See WWDC talk Introducing Watch Connectivity.

You could check WCSession.defaultSession().watchAppInstalled and ask the user to launch the app if it is true.

How to open Settings programmatically like in Facebook app?

You can't, there is no API call to do this.

Only system dialogs, dialogs from Apple Frameworks, can open the settings app.
In iOS 5 there was a app url scheme to open the system dialog but Apple removed it later.


With the coming of iOS 8 you can open the settings dialog on your apps page.

if (&UIApplicationOpenSettingsURLString != NULL) {
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}
else {
// Present some dialog telling the user to open the settings app.
}

how some apps can open setting app programmatically within their app

Apps cannot open the settings application to a specific screen. The reason that apps like MapMyFitness open preferences is because they ask for permission to use Bluetooth Low Energy. Asking for permission is managed by CBCentralManager on first usage.

Sample Image

This is also the class that knows if Bluetooth is turned on or off. It will show an alert automatically with an option to go into settings to turn bluetooth on.

A similar popup will be shown when using location services.

These popups are shown automatically by the system framework. The message can be customized using the purpose property for location services, that is not possible in case of Bluetooth.

No private API was used for this, so there's no reason for the app to be rejected.

Opening the Settings app from another app

As mentioned by Karan Dua this is now possible in iOS8 using UIApplicationOpenSettingsURLString see Apple's Documentation.

Example:

Swift 4.2

UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)

In Swift 3:

UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!)

In Swift 2:

UIApplication.sharedApplication().openURL(NSURL(string:UIApplicationOpenSettingsURLString)!)

In Objective-C

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

Prior to iOS 8:

You can not. As you said this has been covered many times and that pop up asking you to turn on location services is supplied by Apple and not by the App itself. That is why it is able to the open the settings application.

Here are a few related questions & articles:

is it possible to open Settings App using openURL?

Programmatically opening the settings app (iPhone)

How can I open the Settings app when the user presses a button?

iPhone: Opening Application Preferences Panel From App

Open UIPickerView by clicking on an entry in the app's preferences - How to?

Open the Settings app?

iOS: You’re Doing Settings Wrong

Detecting programmatically whether an app is installed on iPhone

UPDATED 8th January 2014 - 3 things you can do

I actually had to do this for a client again. They wanted users to be able to open their second app from the main app if it had been installed.

This is my finding. Use the canOpenURL method to check if an app is installed or/and then use the openURL method to

  1. Open the application installed on the iOS device
  2. Take the user to the app store directly pointing them to the app/your list of developer apps
  3. Take them to a website instead

All code samples available for each scenario

//Find out if the application has been installed on the iOS device
- (BOOL)isMyAppInstalled {
return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"nameOfMyApp:"]];
}

- (IBAction)openOrDownloadApp {
//This will return true if the app is installed on the iOS device
if ([self myAppIsInstalled]){
//Opens the application
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"nameOfMyApp:"]];
}
else { //App is not installed so do one of following:

//1. Take the user to the apple store so they can download the app
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.com/apps/nameOfMyApp"]];

//OR

//2. Take the user to a list of applications from a developer
//or company exclude all punctuation and space characters.
//for example 'Pavan's Apps'
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.com/apps/PavansApps"]];

//OR

//3. Take your users to a website instead, with maybe instructions/information
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.pavan.com/WhyTheHellDidTheAppNotOpen_what_now.html"]];

}
}

Choose one option, I've just spoiled you with choice. Choose one that fits your requirements.
In my case I had to use all three options in different areas of the program.



Related Topics



Leave a reply



Submit