Detect app installation with StoreKit - ios

iOS6 introduced StoreKit framework which is designated for interacting with the AppStore from within the app.
I easily managed to direct the user to a specific app, the question is how can I detect whether the user actually installed the app I redirected him to?

This is usually done by calling -canOpenURL: on UIAplication object like this:
NSURL *appURL = [NSURL URLWithString:#"fb:"];
BOOL appInstalled = [[UIApplication sharedApplication] canOpenURL:appURL];
But you need to know what URL scheme does the second app open. It is declared in Info.plist file by the app developer.

There is an open source framework called "iHasApp" avaiable that can detect installed apps.
Git Repository: iHasApp

Related

How to check if a user installed my app from my another app? iOS (Unity)

I have 2 apps and I want to know if in my app 1, the app 2 is installed (and in my app 2, check if my app 1 is installed).
I know the function :
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:url]]
But the problem is I have to add the urls scheme in LSApplicationQueriesSchemes in my Info.plist but maybe tomorrow I want to develop a third application and I don't want to rebuild all my apps and include my new url scheme inside my application 1 and 2.
Is it possible to check if an user has one of my application by the developer ID or something like that? Without rebuild new version of my apps just for adding 1 url scheme when I release a new app?
Thank you
You can have all your apps use the same "App Group" (google more information on how to set it up, it's easy) and you can create a NSUserDefaults suite using that group identifier.
On launch, each app could write the Appname Installed key to that NSUserDefaults suite and since it's a shared suite between your apps, others could read the value and know if Appname is installed.
The downside of this is that there's no way for your app to know when it's being uninstalled, so if it's installed once the key will show up there even if the app was removed.
The best way to do this is using URL schemes. Each of your app should register a URL scheme it can handle, and then from the other app you call canOpenURL(_:) on UIApplication to test if your app is installed.
Example:
If you have MyApp1 which has registered the URL scheme myapp1://, from your other app you can:
UIApplication.shared.canOpenURL(URL(string: "myapp1://")!)
Pay special attention to the LSApplicationQueriesSchemes key you need to add to your Info.plist. This is needed for this to work and is mentioned on the documentation page I linked above.
Contrary to the application group approach, this will correctly identify when your app is uninstalled.

UIApplication openURL vs NSURLConnection initWithRequest for launching iTunes

I want to launch iTunes via my app. Currently there's a code that's doing that using [NSURLConnection alloc] initWithRequest. I'm thinking about changing it to [UIApplication sharedApplication] openURL.
What is the difference and what is the correct way?
Q: How do I launch the App Store from my iOS app? Also, how do I link to my application on the store?
A: The -[UIApplication openURL:] method handles links to applications and media by launching the appropriate store application for the passed NSURL object. Follow the steps below to obtain a link to an application, music, movie, or TV show sold on iTunes, and link to it from your iOS application:
Launch iTunes on your computer.
Search for the item you want to link to.
Right-click or control-click on the item's name in iTunes, then choose "Copy iTunes Store URL" from the pop-up menu.
In your application, create an NSURL object with the copied iTunes URL, then pass this object to UIApplication' s openURL: method to open your item in the App Store.
Listing 1 Launching the App Store from an iOS application
NSString *iTunesLink = #"https://itunes.apple.com/us/app/apple-store/id375380948?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
see https://developer.apple.com/library/ios/qa/qa1629/_index.html
[UIApplication sharedApplication] openURL used when you need go to another app. In your case its AppStore
iOS Developer Library
Discussion:
The URL can locate a resource in the same or other app. If the resource is another app, invoking this method may cause the calling app to quit so the other one can be launched.
1.[NSURLConnection alloc] initWithRequest: is a way of network request.
you use it if you want to get some data from network
2.[UIApplication sharedApplication] openURL: can open an app according to the param.
I guess you may want to use [UIApplication sharedApplication] openURL:

How to find OpenVPN is installed or not

I searched for OpenURL scheme to find OpenVPN is installed or not.
so far no luck.
is there any other way I can verify?
OpenVPN Connect 1.0.6 and higher installs the openvpn:// URL scheme and can be detected with the following code:
BOOL installed = [application canOpenURL:[NSURL URLWithString:#"openvpn://"]];
Reference
In iOS < 9 you can easily check wether an Application is installed or not, in case you know the exact URL scheme.
For this you could use the functions [[UIApplication sharedApplication] canOpenURL:yourURL] and [[UIApplication sharedApplication] openURL:yourURL]. This functions were used by different Applications to check which Apps are installed to provide custom Ads.
With the Update to iOS 9 this functionality is limited. "Starting on iOS 9, apps will have to declare what URL schemes they would like to be able to check for and open in the configuration files of the app as it is submitted to Apple."(Awkward Hare - Quick Take on iOS 9 URL Scheme Changes)
Edit: URL scheme provided by: Durai Amuthan.H
Best Regards

Opening TestFlight app from another app and deep link to specific app

How do i find the scheme of another app and deep link to it from my own iOS app?
More specifically, I want to deep link to the Testflight app upon certain conditions (set by my code). I'm assuming the person has Testflight installed, (which might be a bad assumption but we can live with that assumption).
I know that on Android, you can query for apps and send intents to deep link to someone else's app. What would be the equivalent on iOS?
There are two things you need to do. First, check to see if TestFlight is installed. Then create a new link to your app.
NSURL *customAppURL = [NSURL URLWithString:#"itms-beta://"];
if ([[UIApplication sharedApplication] canOpenURL:customAppURL]) {
// TestFlight is installed
// Special link that includes the app's Apple ID
customAppURL = [NSURL URLWithString:#"https://beta.itunes.apple.com/v1/app/978489855"];
[[UIApplication sharedApplication] openURL:customAppURL];
}
This special https://beta.itunes.apple.com URL will be opened directly in TestFlight.
Finally, if you are using iOS 9 (or later), you need to make an addition to your Info.plist to get the canOpenURL: method to work.
If your app is linked on or after iOS 9.0, you must declare the URL
schemes you want to pass to this method. Do this by using the
LSApplicationQueriesSchemes array in your Xcode project’s Info.plist
file. For each URL scheme you want your app to use with this method,
add it as a string in this array.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>itms-beta</string>
</array>
From looking at the plist the URL scheme for TestFlight is "itms-beta://" I can't manage to get it deep linking yet, I've tried passing it the Apple ID, with and without a ? along with prefixing it with appleid= I will try bundle ID next.
To open the TestFlight app on the users device you can use:
NSURL *customAppURL = [NSURL URLWithString:#"itms-beta://"];
if ([[UIApplication sharedApplication] canOpenURL:customAppURL]) {
[[UIApplication sharedApplication] openURL:customAppURL];
}
Swift 3/4 answer:
if let customAppURL = URL(string: "itms-beta://"){
if(UIApplication.shared.canOpenURL(customAppURL)){
UIApplication.shared.open(customAppURL, options: [:], completionHandler: nil)
}
}
Most of the built-in applications Apple provides respond to custom URL schemes; for example, the Maps, Mail, YouTube, iTunes, and App Store applications will all open in response to custom URLs. However, there are also many established third-party applications with published URL schemes that you can use in your own application. You can search the applications schemes on
http://handleopenurl.com/
http://wiki.akosma.com/IPhone_URL_Schemes – both have a great list of URL schemes
Once you got the custom URL scheme then you can deep link to that app using the same schema,
NSURL *customAppURL = [NSURL URLWithString:#"urlscheme://"];
//Eg: NSURL *whatsappURL = [NSURL URLWithString:#"whatsapp://send?text=Hello%20World!"];
if ([[UIApplication sharedApplication] canOpenURL:whatsAppURL]) {
[[UIApplication sharedApplication] openURL:whatsAppURL]]];
}
Another way to invoke either one app or another:
- (IBAction)go:(id)sender {
NSString *cnnAppURL = #"cnn://";
NSString *mapsAppURL = #"maps://";
BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:cnnAppURL]];
NSString *url = canOpenURL ? cnnAppURL : mapsAppURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}
Please read "UseYourLoaf's recent blog post on using URLschemes with canOpenURL. This relates to new security concerns and solutions. Quote:
"This is useful but developers including Twitter and Facebook were using this mechanism to discover the list of Apps installed on a device so they can deliver “tailored content”. Apple decided this is a privacy violation and so in iOS 9 restricted the querying of URL schemes. If you build and link against the iOS 9 SDK you need to whitelist the schemes your app will query. What is important to understand is that this policy can also impact older Apps that have not yet been rebuilt with the iOS 9 SDK."
Please read this link on issues related to the canOpenURL function
Read #picciano's last point - this won't work without modifying your app's plist.

How to launch an app using NSURL and -openURL:?

There are a few apps which I find very helpful and want to recommend to my users inside my app. If one such app is installed, and the user taps the button, I want to launch that app. Otherwise open the app page in the App Store app.
UIApplication provides a -canOpenURL: method which I think can be used to check if an app exists on the device. With -openURL: an app can be launched. But how do I construct an NSURL to launch an app?
The apps I want to refer to don't have any special registered URL scheme, at least not that I know of. All I know is their name and app ID.
Is that possible or must the developers of these apps update their apps to support custom URL opening schemes?
It is only possible to open the app by url in case it has known registered URL scheme (it may me your application or one of the existing iOS schemes)
Here is a list of public URL schemes. This however is just a fraction of what is out there in the market. It may however be helpful for you.

Resources