0

特定のアプリがiPhoneデバイスにすでにインストールされているかどうかを確認する方法は?どうすればこれを実現できますか?

4

4 に答える 4

1

canOpenURL基本的に、その特定の URL スキームに登録されているアプリがインストールされているかどうか、つまりアプリが存在するかどうかを確認し、存在する場合は URL を開くことができます。

- (BOOL) appExists: (NSURL*)url{
    if ([[UIApplication sharedApplication] canOpenURL:url]) {        
        return YES;

    } else {
        return NO;
    }
}


NSURL *urlApp = [NSURL URLWithString:@"fb://profile/73728918115"];// facebook app

NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:@"%@", @"twitter:///user?screen_name=INNOVA_ET_BELLA"]];//tweeter app

if ([self appExists:urlApp]) {
        [[UIApplication sharedApplication] openURL:urlApp];
} 

iPhone の URL スキーム:

http://wiki.akosma.com/IPhone_URL_Schemes

カスタム URL スキーム:

http://mobiledevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
于 2012-07-31T09:17:16.630 に答える
0

アプリにURLが登録されている場合、この方法で存在するかどうかを確認できます

[[UIApplication sharedApplication] canOpenURL:url]

URLは次のようなものですskype://

そうでない場合は、すべてのフォルダーをループする必要があります。
方法:グロブを使用してディレクトリ内のファイルのリストを取得する

NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *dirContents = [fm contentsOfDirectoryAtPath:bundleRoot error:nil];
NSPredicate *fltr = [NSPredicate predicateWithFormat:@"self ENDSWITH '.app'"];
NSArray *onlyAPPs = [dirContents filteredArrayUsingPredicate:fltr];

アプリケーションは/var/application/APPNAME.app(よく覚えていれば) にあります。

于 2012-07-31T09:32:22.837 に答える
0

Facebook アプリがインストールされているかどうかをテストする例を次に示します。

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
// Facebook app is installed
 }
于 2013-01-24T04:30:49.873 に答える
0

以下のコードを使用すると、すべてのアプリケーションのリストを取得できます。

 NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
 NSString *sandBoxPath = [bundleRoot stringByDeletingLastPathComponent];
 NSString *appFolderPath = [sandBoxPath stringByDeletingLastPathComponent];

 NSFileManager *fm = [NSFileManager defaultManager];
 NSArray *dirContents = [fm contentsOfDirectoryAtPath:appFolderPath error:nil];

 NSMutableArray *appNames = [[NSMutableArray alloc]init];
 for(NSString *application in dirContents)
 {
      NSString *appPath = [appFolderPath stringByAppendingPathComponent:application];
      NSArray *appcontents = [fm contentsOfDirectoryAtPath:appPath error:nil];
      NSPredicate *fltr = [NSPredicate predicateWithFormat:@"self ENDSWITH '.app'"];
      NSArray *onlyApps = [appcontents filteredArrayUsingPredicate:fltr];
      if(onlyApps.count > 0)
           [appNames addObject:[onlyApps objectAtIndex:0]];
 }

 NSLog(@"%@", [appNames description]);
 [appNames release];
于 2012-07-31T09:26:08.270 に答える