
In many cases of working with an app, we may have a need to access a third-party application from your app. But what if the app which you required is not installed on user’s device? In this case, you can show one message to the user or you can navigate the user to App store to download it.
If you simply navigate them to App store user have to search the app which you need and install. There is a chance to user install a different app than you need. To resolve these type of conflicts we can directly take the user to App store product page of the app which you need.
Rather than making it more tedious we will see how we can redirect the visitor to the specific app’s product page.
We will explain you in detail with an example of redirecting to a Google maps product page in the App Store.
1.The first step is to check whether the particular app is installed on the phone or not. In this case, it is Google Maps. The below defines the app to be checked. To check the same add this code in info.plist. If you want to check other apps like Facebook or Twitter, kindly read their documentation how to check whether it installed or not. The following details are got from Google maps docs.
<key>LSApplicationQueriesSchemes</key> <array> <string>comgooglemaps-x-callback</string> <string>comgooglemaps</string> </array>
2.The second step will check if the google maps app is installed or not. The following code will check for the same.
/**Check whether Google map app installed in device or not*/ func isGoogleMapsInstalled() -> Bool { if let url = URL(string: "comgooglemaps://") { return UIApplication.shared.canOpenURL(url) } return false }
3.In the case of the app not being installed on your user’s device, you will give a redirect link to the particular product page. For that, you need to get the specific app’s product page. This can be done by the following steps.
->Visit https://linkmaker.itunes.apple.com.
->In the search bar, type the name of the app to be downloaded. And select Media Type as iOS apps.
->Now you will get the list of apps and chose the right one.
->In the app link page, you will see the direct link to the app. In this case the direct link to the Google Maps app. Copy the link.
4.Opening google maps product page from your app
func openGoogleMapsProductPage() { if let url = URL(string: "https://itunes.apple.com/us/app/google-maps-gps-navigation/id585027354?mt=8") { if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:], completionHandler: nil) return } } }
This is how the code has to be written for redirecting to any app’s product page in the App Store. As we mentioned the complete code for redirecting to download the Google maps app page is given below.
Complete code:
/**Navigate the user to Google maps with source and destination address*/ func navigateToGoogleMaps(address: String?) { if let address = address { if isGoogleMapsInstalled() { // Check whether google maps installed in iPad // Google maps is installed in user device, take proper action. } else { // Google maps is not installed in device. self.openGoogleMapsProductPage() } } } // Check google maps is installed in users device or not. func isGoogleMapsInstalled() -> Bool { if let url = URL(string: "comgooglemaps://") { return UIApplication.shared.canOpenURL(url) } return false } // Navigate user to google maps product page in App Store func openGoogleMapsProductPage() { let googleMapsPageLink = "https://itunes.apple.com/us/app/google-maps-gps-navigation/id585027354?mt=8" // Link got from link maker website. if let url = URL(string: googleMapsPageLink) { if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:], completionHandler: nil) return } } }
In this post, we have seen how to redirect you to the product page of a third party app’s product page in App store. This eases up the process of installing a third party app on your phone when necessary. We have seen the process for it for iOS development.
–
Karthick S,
iOS Team,
Mallow Technologies.