美文网首页
通过Bundle ID 唤醒App

通过Bundle ID 唤醒App

作者: 旭日飞扬 | 来源:发表于2018-08-02 13:28 被阅读403次

    1:查看手机中安装的所有App的包名

    • (void)GetPackageName{
      Class lsawsc = NSClassFromString(@"LSApplicationWorkspace");
      NSObject* workspace = [lsawsc performSelector:NSSelectorFromString(@"defaultWorkspace")];
      NSArray *Arr = [workspace performSelector:NSSelectorFromString(@"allInstalledApplications")];
      for (NSString * tmp in Arr)
      {
      NSString * bundleid = [self getParseBundleIdString:tmp];
      NSLog(@"%@",bundleid);
      }

    }

    • (NSString *)getParseBundleIdString:(NSString *)description
      {
      NSString * ret = @"";
      NSString * target = [description description];

      // iOS8.0 "LSApplicationProxy: com.apple.videos",
      // iOS8.1 "<LSApplicationProxy: 0x898787998> com.apple.videos",
      // iOS9.0 "<LSApplicationProxy: 0x145efbb0> com.apple.PhotosViewService <file:///Applications/PhotosViewService.app>"

      if (target == nil)
      {
      return ret;
      }
      NSArray * arrObj = [target componentsSeparatedByString:@" "];
      switch ([arrObj count])
      {
      case 2: // [iOS7.0 ~ iOS8.1)
      case 3: // [iOS8.1 ~ iOS9.0)
      {
      ret = [arrObj lastObject];
      }
      break;

        case 4: // [iOS9 +)
        {
            ret = [arrObj objectAtIndex:2];
        }
            break;
            
        default:
            break;
      

      }
      return ret;
      }

    2:通过准确的包名唤起App

    • (void)OpenApp{

      Class lsawsc = NSClassFromString(@"LSApplicationWorkspace");
      NSObject* workspace = [lsawsc performSelector:NSSelectorFromString(@"defaultWorkspace")];
      // iOS6 没有defaultWorkspace
      if ([workspace respondsToSelector:NSSelectorFromString(@"openApplicationWithBundleID:")])
      {
      [workspace performSelector:NSSelectorFromString(@"openApplicationWithBundleID:") withObject:@"com.Calendar"];

      }

    }

    相关文章

      网友评论

          本文标题:通过Bundle ID 唤醒App

          本文链接:https://www.haomeiwen.com/subject/saijvftx.html