2011-08-24 13 views

Respuesta

11

Si la aplicación admite un esquema de URL personalizado, puede marcar UIApplication-canOpenURL:. Eso solo le dirá que una aplicación capaz de abrir ese esquema de url está disponible, no necesariamente la aplicación que es. No hay un mecanismo disponible públicamente para inspeccionar qué otras aplicaciones ha instalado un usuario en su dispositivo.

Si controla ambas aplicaciones, también puede utilizar un llavero o un cartón para compartir entre ellas con más detalle.

8

Puede comprobar de esta manera, así:

BOOL temp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"yourAppURL://"]]; 
            
if(!temp) 
{ 
    NSLog(@"INVALID URL"); //Or alert or anything you want to do here 
} 
+3

La primera línea no se compila para mí, pero esto hizo: 'temp BOOL = [[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString: @ "yourAppURL: //"]];' – newenglander

+0

lo siento, pero lo es la URL de la aplicación? ¿es el nombre de la aplicación o algo así? – ColdSteel

0

para los usuarios de SWIFT

 let urlPath: String = "fb://www.facebook.com" 
    let url: NSURL = NSURL(string: urlPath)! 

    let isInstalled = UIApplication.sharedApplication().canOpenURL(url) 
    if isInstalled { 
     print("Installed") 
    }else{ 
     print("Not installed") 
    } 
0

Facebook utiliza esta https://github.com/facebook/facebook-ios-sdk/blob/master/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKInternalUtility.m internamente, puede hacer lo mismo

#define FBSDK_CANOPENURL_FACEBOOK @"fbauth2" 

+ (BOOL)isFacebookAppInstalled 
{ 
    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
    [FBSDKInternalUtility checkRegisteredCanOpenURLScheme:FBSDK_CANOPENURL_FACEBOOK]; 
    }); 
    NSURLComponents *components = [[NSURLComponents alloc] init]; 
    components.scheme = FBSDK_CANOPENURL_FACEBOOK; 
    components.path = @"/"; 
    return [[UIApplication sharedApplication] 
      canOpenURL:components.URL]; 
} 

Código de Swift 3

static func isFacebookAppInstalled() -> Bool { 
    let schemes = ["fbauth2", "fbapi", "fb"] 
    let schemeUrls = schemes.flatMap({ URL(string: "\($0)://") }) 

    return !schemeUrls.filter({ UIApplication.shared.canOpenURL($0) }).isEmpty 
} 
Cuestiones relacionadas