zoukankan      html  css  js  c++  java
  • iPhone获取手机里面所有的APP(私有库)+ 通过包名打开应用

    1.获取到手机里面所有的APP包名

    - (void)touss
    {
        Class lsawsc = objc_getClass("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正在下载,通过这个去打开。是yes状态,但是实际上这个应用根本没有下载下来。

        Class lsawsc = objc_getClass("LSApplicationWorkspace");
        NSObject* workspace = [lsawsc performSelector:NSSelectorFromString(@"defaultWorkspace")];
        // iOS6 没有defaultWorkspace
        if ([workspace respondsToSelector:NSSelectorFromString(@"openApplicationWithBundleID:")])
        {
            [workspace performSelector:NSSelectorFromString(@"openApplicationWithBundleID:") withObject:@"com.Calendar.jbp"];
        }
  • 相关阅读:
    Linux使用Public Key方式远程登录
    Linux编译安装Mariadb数据库
    Centos7环境搭建lnmp环境
    浅谈Java中的System.gc()的工作原理
    Eclipse快捷键大全(转载)
    java中的参数传递——值传递、引用传递
    Visual Studio 2017 安装后无法创建c++或MFC项目
    ubuntu sendmail配置发送邮件
    ubuntu11.0静态IP地址配置
    cin与cout详解
  • 原文地址:https://www.cnblogs.com/fuunnyy/p/5392241.html
Copyright © 2011-2022 走看看