[转帖]IOS通过程序如何获取本地应用程序信息_VMware, Unix及操作系统讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  VMware, Unix及操作系统讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 3690 | 回复: 0   主题: [转帖]IOS通过程序如何获取本地应用程序信息        下一篇 
clover
注册用户
等级:少校
经验:843
发帖:73
精华:0
注册:2013-6-28
状态:离线
发送短消息息给clover 加好友    发送短消息息给clover 发消息
发表于: IP:您无权察看 2013-6-28 13:18:34 | [全部帖] [楼主帖] 楼主

最近要写一个项目,需要获取本地应用程序的相关信息。发现在iphone上的设置-用量里可以找到本地应用程序的信息,求有什么代码上的方法实现获取应用信息,除了越狱以外,如果通过向苹果公司申请一些授权可以获取也请帮忙告诉我,多谢!

解决办法:

用到私有API:

BOOL APCheckIfAppInstalled(NSString *bundleIdentifier){
      static NSString *const cacheFileName = @"com.apple.mobile.installation.plist";
      NSString *relativeCachePath = [[@"Library" stringByAppendingPathComponent: @"Caches"] stringByAppendingPathComponent: cacheFileName];
      NSDictionary *cacheDict = nil;
      NSString *path = nil;
      NSLog(@"relativeCachePath:%@",relativeCachePath);
      // Loop through all possible paths the cache could be in
      for (short i = 0; 1; i++) {
            switch (i) {
                  case 0: // Jailbroken apps will find the cache here; their home directory is /var/mobile
                  path = [NSHomeDirectory() stringByAppendingPathComponent: relativeCachePath];
                  break;
                  case 1: // 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;
                  case 2: // 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;
            NSLog(@"path:%@",path);
            // Ensure that file exists
            if ([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir] && !isDir){
                  cacheDict = [NSDictionary dictionaryWithContentsOfFile: path];
            }
            // If cache is loaded, then break the loop. If the loop is not "broken," it will return NO later (default: case)
            if (cacheDict){
                  NSLog(@"cacheDict:%@",cacheDict);
                  break;
            }
      }
      NSLog(@"gggg");
      // First check all system (jailbroken) apps
      NSDictionary *system = [cacheDict objectForKey: @"System"];
      NSLog(@"system:%@",system);
      if ([system objectForKey: bundleIdentifier]){
            return YES;
      }
      // Then all the user (App Store /var/mobile/Applications) apps
      NSDictionary *user = [cacheDict objectForKey: @"User"];
      NSLog(@"user:%@",user);
      if ([user objectForKey: bundleIdentifier]){
            return YES;
      }
      // If nothing returned YES already, we'll return NO now
      return NO;
}




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论