Question

Je suis dans cette situation où je dois afficher un bouton qui dit « Open myApp » (si myApp est installé sur l'appareil) ou il dit « Télécharger myApp » (si myApp est pas installé sur l'appareil) dans un iphone app. Pour ce faire, je dois détecter si une application (avec une URL personnalisée connue) a été installé sur l'appareil. Comment puis-je faire ceci? Merci à l'avance.

Était-ce utile?

La solution

MISE À JOUR 8 Janvier 2014 - 3 choses que vous pouvez faire

J'ai dû le faire pour un client nouveau. Ils voulaient que les utilisateurs puissent ouvrir leur deuxième application à partir de l'application principale si elle avait été installée.

Ceci est ma conclusion. Utilisez la méthode canOpenURL pour vérifier si une application est installée ou / et ensuite utiliser la méthode openURL à

  1. Ouvrez l'application installée sur l'appareil iOS
  2. l'utilisateur vers l'App Store les pointant directement à l'application / votre liste d'applications développeur
  3. Prenez-les à un site Web à la place

Tous les échantillons de code disponibles pour chaque scénario

//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"]];

    } 
}

Choisissez une option, je viens de vous l'embarras du choix. Choisissez celle qui correspond à vos besoins. Dans mon cas, je devais utiliser les trois options dans différents domaines du programme.

Autres conseils

Si le schéma d'URL pour votre application est "myapp:", puis

BOOL myAppInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"myapp:"]];

(Nécessite iOS 3.0.)

Pour vérifier l'application est d'installer dans l'appareil ou non

1) Dans info.plist ajouter LSApplicationQueriesSchemes comme exemple ci-dessous

 ici

2) et dans les types d'URL

 ici

3) Maintenant, pour vérifier l'application est installer ou pas

- (IBAction)openAppPressed:(UIButton *)sender {
    NSString *urlString = @"XYZAPP://";
    NSURL *url = [NSURL URLWithString:urlString];

    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
    }
    else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itunes link for download app"]];
    }
}

Vous pouvez ajouter simple balise meta dans la tête d'une page qui a besoin de cette application reniflage.

Pour plus d'informations, rendez-vous ici:

http://developer.apple .com / bibliothèque / ios / # documentation / AppleApplications / Référence / SafariWebContent / PromotingAppswithAppBanners / PromotingAppswithAppBanners.html

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top