iOS 獲取手機(jī)安裝的所有app信息

獲取手機(jī)上所有的app信息

#pragma mark ––––––––––––– 獲取手機(jī)上所有的應(yīng)用
/// iOS12+
- (void)getAppInfoList {
    Class LSApplicationWorkspace = objc_getClass("LSApplicationWorkspace");
    Class LSApplicationProxy = objc_getClass("LSApplicationProxy");

    id defaultWorkspace = [LSApplicationWorkspace performSelector:@selector(defaultWorkspace)];
  
    // 此方法在iOS12+獲取不到
//    id allApplications = [defaultWorkspace performSelector:@selector(allInstalledApplications)];
    NSArray *plugins = [defaultWorkspace performSelector:@selector(installedPlugins)];
    
    NSMutableSet *list = [[NSMutableSet alloc] init];
    for (id plugin in plugins) {
        id bundle = [plugin performSelector:@selector(containingBundle)];
        if (bundle) {
            [list addObject:bundle];
        }
    }

    // 遍歷所有app信息
    for (id plugin in list) {
        // BundleID
        NSString *bundleIdentifier = [plugin performSelector:@selector(bundleIdentifier)];
        if (![bundleIdentifier containsString:@"com.apple"]) {
            NSLog(@"bundleIdentifier -> %@", bundleIdentifier);
        
        NSString *applicationDSID = [plugin performSelector:@selector(applicationDSID)];
        NSLog(@"applicationDSID -> %@", applicationDSID);

        NSString *applicationIdentifier = [plugin performSelector:@selector(applicationIdentifier)];
        NSLog(@"applicationIdentifier -> %@", applicationIdentifier);

        NSString *applicationType = [plugin performSelector:@selector(applicationType)];
        NSLog(@"applicationType -> %@", applicationType);

        NSString *dynamicDiskUsage = [plugin performSelector:@selector(dynamicDiskUsage)];
        NSLog(@"dynamicDiskUsage -> %@", dynamicDiskUsage);

        NSString *itemID = [plugin performSelector:@selector(itemID)];
        NSLog(@"itemID -> %@", itemID);

        NSString *itemName = [plugin performSelector:@selector(itemName)];
        NSLog(@"itemName -> %@", itemName);

        NSString *minimumSystemVersion = [plugin performSelector:@selector(minimumSystemVersion)];
        NSLog(@"minimumSystemVersion -> %@", minimumSystemVersion);

        NSString *requiredDeviceCapabilities = [plugin performSelector:@selector(requiredDeviceCapabilities)];
        NSLog(@"requiredDeviceCapabilities -> %@", requiredDeviceCapabilities);

        NSString *sdkVersion = [plugin performSelector:@selector(sdkVersion)];
        NSLog(@"sdkVersion -> %@", sdkVersion);

        NSString *shortVersionString = [plugin performSelector:@selector(shortVersionString)];
        NSLog(@"shortVersionString -> %@", shortVersionString);

        NSString *sourceAppIdentifier = [plugin performSelector:@selector(sourceAppIdentifier)];
        NSLog(@"sourceAppIdentifier -> %@", sourceAppIdentifier);

        NSString *staticDiskUsage = [plugin performSelector:@selector(staticDiskUsage)];
        NSLog(@"staticDiskUsage -> %@", staticDiskUsage);

        NSString *teamID = [plugin performSelector:@selector(teamID)];
        NSLog(@"teamID -> %@", teamID);

        NSString *vendorName = [plugin performSelector:@selector(vendorName)];
        NSLog(@"vendorName -> %@", vendorName);
        }
    }
}

/// iOS10 -12屯援,判斷是否安裝app
- (BOOL)isAppInstalled:(NSString *)bundleId {
    NSBundle *container = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/MobileContainerManager.framework"];
    if ([container load]) {
        Class appContainer = NSClassFromString(@"MCMAppContainer");
        
        id install = [appContainer performSelector:@selector(containerWithIdentifier:error:) withObject:bundleId];
        if (install) {
            return YES;
        }
    }
    return NO;
}

/// iOS10-
- (void)getAppInfoList10 {
    Class LSApplicationWorkspace = objc_getClass("LSApplicationWorkspace");
    NSObject* workspace = [LSApplicationWorkspace performSelector:@selector(defaultWorkspace)];
    NSArray *allApplications = [workspace performSelector:@selector(allApplications)];

    Class LSApplicationProxy = object_getClass(@"LSApplicationProxy");
    for (LSApplicationProxy in allApplications) {
        // 查看一些信息
        NSString *bundleID = [LSApplicationProxy performSelector:@selector(applicationIdentifier)];
        NSString *version =  [LSApplicationProxy performSelector:@selector(bundleVersion)];
        NSString *shortVersionString =  [LSApplicationProxy performSelector:@selector(shortVersionString)];
        
        NSLog(@"bundleID -> %@", bundleID);
    }
}

根據(jù)bundleId打開app

//    YES:可以打開  NO:不可以打開
  BOOL isOpenApp = [self isOpenApp:@"com.xxx.demo"];
    NSLog(@"111======%d",isOpenApp);

//根據(jù)bundleID打開app
/// 直接打開某個(gè)APP
- (BOOL)isOpenApp:(NSString*)bundleIdentifier {
    Class LSApplicationWorkspace = objc_getClass("LSApplicationWorkspace");
    NSObject *workspace = [LSApplicationWorkspace performSelector:@selector(defaultWorkspace)];
    // 沒有安裝返回NO
    BOOL isOpenApp = [workspace performSelector:@selector(openApplicationWithBundleID:) withObject:bundleIdentifier];
    return isOpenApp;
}

參考文章:http://www.reibang.com/p/6b1fa5e5cd5b

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末致稀,一起剝皮案震驚了整個(gè)濱河市蒋歌,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,544評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異漓帚,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)午磁,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評論 3 392
  • 文/潘曉璐 我一進(jìn)店門尝抖,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人漓踢,你說我怎么就攤上這事牵署。” “怎么了喧半?”我有些...
    開封第一講書人閱讀 162,764評論 0 353
  • 文/不壞的土叔 我叫張陵奴迅,是天一觀的道長。 經(jīng)常有香客問我,道長取具,這世上最難降的妖魔是什么脖隶? 我笑而不...
    開封第一講書人閱讀 58,193評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮暇检,結(jié)果婚禮上产阱,老公的妹妹穿的比我還像新娘。我一直安慰自己块仆,他們只是感情好构蹬,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,216評論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著悔据,像睡著了一般庄敛。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上科汗,一...
    開封第一講書人閱讀 51,182評論 1 299
  • 那天藻烤,我揣著相機(jī)與錄音,去河邊找鬼头滔。 笑死怖亭,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的坤检。 我是一名探鬼主播兴猩,決...
    沈念sama閱讀 40,063評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼早歇!你這毒婦竟也來了峭跳?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,917評論 0 274
  • 序言:老撾萬榮一對情侶失蹤缺前,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后悬襟,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體衅码,經(jīng)...
    沈念sama閱讀 45,329評論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,543評論 2 332
  • 正文 我和宋清朗相戀三年脊岳,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了逝段。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,722評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡割捅,死狀恐怖奶躯,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情亿驾,我是刑警寧澤嘹黔,帶...
    沈念sama閱讀 35,425評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站莫瞬,受9級特大地震影響儡蔓,放射性物質(zhì)發(fā)生泄漏郭蕉。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,019評論 3 326
  • 文/蒙蒙 一喂江、第九天 我趴在偏房一處隱蔽的房頂上張望召锈。 院中可真熱鬧,春花似錦获询、人聲如沸涨岁。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,671評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽梢薪。三九已至,卻和暖如春瓦戚,著一層夾襖步出監(jiān)牢的瞬間沮尿,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,825評論 1 269
  • 我被黑心中介騙來泰國打工较解, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留畜疾,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,729評論 2 368
  • 正文 我出身青樓印衔,卻偏偏與公主長得像啡捶,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子奸焙,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,614評論 2 353

推薦閱讀更多精彩內(nèi)容