Comment faire pour vérifier et ouvrir une application existante dans iOS 8 par programmation?

Je veux vérifier si une application est présente dans mon iphone ou non. S'il est présent, je veux le lancer sinon ouvrir le lien App Store de l'application.

Veuillez suggérer les parameters requirejs pour le faire et la façon de l'implémenter.

J'ai le lien App Store pour ouvrir l'application mais j'ai besoin de vérifier si l'application est déjà présente dans le téléphone.

essayez ce code

Swift 2,2

@IBAction func openInstaApp(sender: AnyObject) { var instagramHooks = "instagram://user?username=your_username" var instagramUrl = NSURL(ssortingng: instagramHooks) if UIApplication.sharedApplication().canOpenURL(instagramUrl!) { UIApplication.sharedApplication().openURL(instagramUrl!) } else { //redirect to safari because the user doesn't have Instagram println("App not installed") UIApplication.sharedApplication().openURL(NSURL(ssortingng: "https://itunes.apple.com/in/app/instagram/id389801252?m")!) } } 

rapide 3

  @IBAction func openInstaApp(sender: AnyObject) { let instagramHooks = "instagram://user?username=your_username" let instagramUrl = URL(ssortingng: instagramHooks) if UIApplication.shared.canOpenURL(instagramUrl! as URL) { UIApplication.shared.open(instagramUrl!) } else { //redirect to safari because the user doesn't have Instagram print("App not installed") UIApplication.shared.open(URL(ssortingng: "https://itunes.apple.com/in/app/instagram/id389801252?m")!) } } 

Pour ouvrir une application à partir d'une autre application, vous devez exposer un schéma d'URL à partir de l'application que vous souhaitez ouvrir.

Si l'application peut être ouverte en utilisant la fonction openURL (qui utilise le schéma d'URL personnalisé exposé), l'user peut accéder directement à votre application.

Si ce n'est pas le cas, vous pouvez ouvrir la page de l'application openURL l'aide de la fonction openURL , en fournissant l'URL de l'application itunes.

Voici une idée complète sur la façon de l'atteindre.

Vous pouvez vérifier si l'application est disponible ou non à l'aide de la fonctionnalité iOS, puis ouvrez l'URL iTunes. Essayez le code suivant pour votre solution:

Commencez par définir le model d'URL "testapp" dans votre application iTunes, puis utilisez le code suivant dans l'autre application à partir de laquelle vous souhaitez ouvrir votre application:

 -(IBAction) openApp:(id)sender { // Opens the app if installed, otherwise displays an error UIApplication *yourApplication = [UIApplication sharedApplication]; NSSsortingng *URLEncodedText = [self.textBox.text ssortingngByAddingPercentEscapesUsingEncoding:NSUTF8SsortingngEncoding]; NSSsortingng *ourPath = [@"testapp://" ssortingngByAppendingSsortingng:URLEncodedText]; NSURL *ourURL = [NSURL URLWithSsortingng:ourPath]; if ([yourApplication canOpenURL:ourURL]) { [yourApplication openURL:ourURL]; } else { //The App is not installed. It must be installed from iTunes code. NSSsortingng *iTunesLink = @"//Your itunes Url"; [[UIApplication sharedApplication] openURL:[NSURL URLWithSsortingng:iTunesLink]]; } } 

Vous pouvez vérifier si une application est installée sur le périphérique correspondant à l'aide de:

 // url = "example" (check the following image to understand) let canOpen = UIApplication.sharedApplication().canOpenURL(NSURL(ssortingng: url as Ssortingng)!) 

url est pré-configuré (avoir un schéma d'URL enregistré pour votre application dans votre Info.plist)

Donc, si canOpen est true signifie que l'application est installée et vous pouvez ouvrir en utilisant:

 UIApplication.sharedApplication().openURL(NSURL(ssortingng:url)!) 

entrez la description de l'image ici

Vous devez utiliser des schémas d'URL. L'idée est la suivante:

La définition d'un identifiant d'URL pour vos applications le fait reconnaître par d'autres applications. Juste comme ça, l'application que vous voulez ouvrir doit avoir un identifiant d'URL personnalisé. Google il pour l'identifiant URL personnalisé de votre application souhaitée. Utilisez le lien ci-dessous pour reference sur l'utilisation des schémas d'URL.

Pour reference

Site pour vérifier les identifiants d' URL pour les applications

 let naviURL = NSURL(ssortingng: "yandexnavi://build_route_on_map?lat_from=55.751802&lon_from=37.586684&lat_to=55.758192&lon_to=37.642817")! let res = UIApplication.sharedApplication().openURL(naviURL) if !res { let appStoreURL = NSURL(ssortingng: "itms://itunes.apple.com/ru/app/andeks.navigator/id474500851?mt=8")! UIApplication.sharedApplication().openURL(appStoreURL) }