zoukankan      html  css  js  c++  java
  • ios是否安装了某应用

    分2中情况:

    1.越狱之后的设备,可以获取完整的列表,获取也比较方便,方法如下:
    http://stackoverflow.com/questions/3878197/is-it-possible-to-get-information-about-all-apps-installed-on-iphone/3878220#3878220

    http://www.iphonedevsdk.com/forum/iphone-sdk-development/22289-possible-retrieve-these-information.html 

    也有如下代码可以获取:
    NSFileManager* fileManager = [NSFileManager defaultManager];
    NSMutableArray* applist = [NSMutableArray arrayWithCapacity:10];
    for (NSString *path in [fileManager directoryContentsAtPath:@"/var/mobile/Applications"]) {
    for (NSString *subpath in [fileManager directoryContentsAtPath:
    [NSString stringWithFormat:@"/var/mobile/Applications/%@", path]]) {
    if ([subpath hasSuffix:@".app"])
    {
    NSString* infoplist = [NSString stringWithFormat:@"/var/mobile/Applications/%@/%@/Info.plist", path, subpath];
    NSLog(@"sdfsadfa0%@",infoplist);
    NSDictionary* dict = [NSDictionary dictionaryWithContentsOfFile:infoplist];
    NSLog(@"sdfsadfa1%@",dict);

    [applist addObject:[dict objectForKey:@"CFBundleDisplayName"]];
    }
    }
    住:代码运行的目录为/Applications/




    ****************************************
    // Declaration

    BOOL APCheckIfAppInstalled(NSString*bundleIdentifier);// Bundle identifier (eg. com.apple.mobilesafari) used to track apps

    // Implementation

    BOOL APCheckIfAppInstalled(NSString*bundleIdentifier)
    {
    staticNSString*const cacheFileName =@\"com.apple.mobile.installation.plist\";
    NSString*relativeCachePath =[[@\"Library\" stringByAppendingPathComponent:@\"Caches\"] stringByAppendingPathComponent: cacheFileName];
    NSDictionary*cacheDict =nil;
    NSString*path =nil;
    // Loop through all possible paths the cache could be in
    for(short i =0;1; i++)
    {

    switch(i){
    case0:// Jailbroken apps will find the cache here; their home directory is /var/mobile
    path =[NSHomeDirectory() stringByAppendingPathComponent: relativeCachePath];
    break;
    case1:// App Store apps and Simulator will find the cache here; home (/var/mobile/) is 2 directories above sandbox folder
    path =[[NSHomeDirectory() stringByAppendingPathComponent:@\"../..\"] stringByAppendingPathComponent: relativeCachePath];
    break;
    case2:// If the app is anywhere else, default to hardcoded /var/mobile/
    path =[@\"/var/mobile\" stringByAppendingPathComponent: relativeCachePath];
    break;
    default:// Cache not found (loop not broken)
    return NO;
    break;}

    BOOL isDir = NO;
    if([[NSFileManager defaultManager] fileExistsAtPath: path isDirectory:&isDir]&&!isDir)// Ensure that file exists
    cacheDict =[NSDictionary dictionaryWithContentsOfFile: path];

    if(cacheDict)// If cache is loaded, then break the loop. If the loop is not \"broken,\" it will return NO later (default: case)
    break;
    }

    NSDictionary*system =[cacheDict objectForKey:@\"System\"];// First check all system (jailbroken) apps
    if([system objectForKey: bundleIdentifier])return YES;
    NSDictionary*user =[cacheDict objectForKey:@\"User\"];// Then all the user (App Store /var/mobile/Applications) apps
    if([user objectForKey: bundleIdentifier])return YES;

    // If nothing returned YES already, we'll return NO now
    return NO;
    }


    Here is an example of this, assuming that your app is named "yourselfmadeapp" and is an app in the app store. 


    NSArray*bundles2Check =[NSArray arrayWithObjects:@\"com.apple.mobilesafari\",@\"com.yourcompany.yourselfmadeapp\",@\"com.blahblah.nonexistent\",nil];
    for(NSString*identifier in bundles2Check)
    if(APCheckIfAppInstalled(identifier))
    NSLog(@\"App installed:%@\", identifier);
    else
    NSLog(@\"Appnot installed:%@\", identifier);


    Log Output:


    2009-01-3012:19:20.250SomeApp[266:20b]App installed: com.apple.mobilesafari
    2009-01-3012:19:20.254SomeApp[266:20b]App installed: com.yourcompany.yourselfmadeapp
    2009-01-3012:19:20.260SomeApp[266:20b]Appnot installed: com.blahblah.nonexistent
  • 相关阅读:
    般若与慈悲
    四谛
    Mysql:8.0.19:新特性、过期、已经删除的
    Mysql:As of 8.0.16:--validate-config:新增的服务器配置验证特效:good!
    Mysql:FIPS:Federal Information Processing Standards 140-2:世上有不透风的墙么?!
    ASP.NET Core WebApi使用Swagger生成API说明文档【xml注释版】
    ASP.NET Core WebApi使用Swagger生成API说明文档【特性版】
    Idea导入Eclipse的Web项目并部署到Tomcat
    在.Net中使用RedLock实现分布式锁
    【转】在C#中使用Json.Net进行序列化和反序列化及定制化
  • 原文地址:https://www.cnblogs.com/qq378829867/p/2780916.html
Copyright © 2011-2022 走看看