簡體   English   中英

在 iphone 上查找已安裝的應用程序列表

[英]Finding list of installed apps on iphone

是否可以通過編程方式找出我的 iOS 設備上安裝的所有應用程序的名稱? 是否有相同的 API 可用?

感謝您的幫助

不,由於沙盒環境,iOS 應用程序無法訪問其他應用程序的信息/關於其他應用程序的信息。

是的,可以獲取所有已安裝應用程序的列表

-(void) allInstalledApp
{    
    NSDictionary *cacheDict;

    NSDictionary *user;

    static NSString *const cacheFileName = @"com.apple.mobile.installation.plist";

    NSString *relativeCachePath = [[@"Library" stringByAppendingPathComponent: @"Caches"] stringByAppendingPathComponent: cacheFileName];

    NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent: @"../.."] stringByAppendingPathComponent: relativeCachePath];

    cacheDict    = [NSDictionary dictionaryWithContentsOfFile: path];

    user = [cacheDict objectForKey: @"User"];

    NSDictionary *systemApp=[cacheDict objectForKey:@"System"];
}   

systemApp Dictionary包含所有系統相關應用程序的列表, user Dictionary包含其他應用程序信息。

有很多方法可以在沒有越獄設備的情況下做到這一點,並且不會讓您的應用程序被拒絕。
1. 獲取當前正在運行的進程列表,請參閱SO 答案。 您需要將進程名稱轉換為應用程序名稱。
2. 檢查是否有任何應用程序使用 UIApplicationDelegate canOpenURL 注冊了唯一的 URL 方案。 有幾個站點對已知的 url 方案進行編目,是最好的一個。

如果應用程序當前未運行且未注冊自定義 url 方案,則這些方法不會檢測到它。 我有興趣聽到一種在應用程序商店中允許的比這更好的方法。

不是來自設備。 但是,您可以從桌面查看 iTunes 資料庫。

試試這個,它甚至可以在非越獄設備上工作:

#include <objc/runtime.h>
Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
SEL selector=NSSelectorFromString(@"defaultWorkspace");

NSObject* workspace = [LSApplicationWorkspace_class performSelector:selector];

SEL selectorALL = NSSelectorFromString(@"allApplications");

NSLog(@"apps: %@", [workspace performSelector:selectorALL]);//will give you all **Bundle IDS** of user's all installed apps

您可以通過使用canOpenURL方法檢查應用程序是否已安裝或檢查后台進程並將它們與您感興趣的應用程序名稱進行匹配來實現。

您可以使用運行時目標 c 來獲取所有已安裝應用程序的列表。 它將為您提供一組LSApplicationProxy對象。

以下是打印設備中安裝的所有應用程序名稱的代碼片段。

Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
NSObject* workspace = [LSApplicationWorkspace_class performSelector:NSSelectorFromString(@"defaultWorkspace")];
NSMutableArray *array = [workspace performSelector:NSSelectorFromString(@"allApplications")];

NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
for (id lsApplicationProxy in array) {
    if(nil != [lsApplicationProxy performSelector:NSSelectorFromString(@"itemName")]){
        [mutableArray addObject:[lsApplicationProxy performSelector:NSSelectorFromString(@"itemName")]];
    }
}
NSLog(@"********* Applications List ************* : \n %@",mutableArray);

不要忘記包含<objc/runtime.h>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM