zoukankan      html  css  js  c++  java
  • iOS获取已安装的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.通过包名打开应用

    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"];
        }
    

      

  • 相关阅读:
    想用Nginx代理一切?行!
    [SuProxy]Ngnix+Lua 实现SSH2,LDAP,ORACLE,SQLSERVER等TCP/IP协议分析,劫持,代理,会话及负载
    hive分区表详细介绍
    hive 中自定义UDF函数和自定义UDTF函数
    yarn工作原理
    HDFS小文件问题
    HDFS读写流程
    利用 canvas 实现签名效果
    idea里面自带的翻译插件
    idea的set,get插件
  • 原文地址:https://www.cnblogs.com/yangyuxiaozi/p/6908850.html
Copyright © 2011-2022 走看看