在iOS设备中,所有用户应用程序都位于/var/mobile/Applications
目录中,每个应用程序都有一个唯一的随机uuid作为其目录名称,例如:
/var/mobile/Applications/15FD62FD-2BEB-4C1E-A9B8-BC93E5C721CC
uuid是15FD62FD-2BEB-4C1E-A9B8-BC93E5C721CC
。
现在我想通过应用程序的包标识符获取目录,我的解决方案是枚举/var/mobile/Applications
目录,从Info.plist
获取包标识符并检查。
这个解决方案相当慢,有没有更快的方法呢?
e.g。如果有一个plist将bundle id记录到uuid映射,那么我可以读取该文件以避免目录枚举。
答案 0 :(得分:10)
我认为你要找的文件是
/var/mobile/Library/Caches/com.apple.mobile.installation.plist
例如,它包含每个应用的类似信息:
"com.zillow.ZillowMap" = {
ApplicationDSID = 216284405;
ApplicationType = User;
CFBundleDisplayName = Zillow;
CFBundleExecutable = ZillowMap;
CFBundleIconFiles = (
"app-icon",
"app-icon-iPad.png",
"app-icon-iPad@2x.png"
);
CFBundleIcons = {
CFBundlePrimaryIcon = {
CFBundleIconFiles = (
"app-icon",
"app-icon-iPad.png",
"app-icon-iPad@2x.png"
);
UIPrerenderedIcon = 1;
};
};
CFBundleIdentifier = "com.zillow.ZillowMap";
CFBundleName = ZillowMap;
CFBundleShortVersionString = "6.1.0112";
CFBundleVersion = "6.1.0112";
CodeInfoIdentifier = "com.zillow.ZillowMap";
Container = "/private/var/mobile/Applications/B9284FBE-E558-4A65-A7E4-AE20CDAD9A1D";
Entitlements = {
"application-identifier" = "JEWMY3RZ4A.com.zillow.ZillowMap";
"aps-environment" = production;
};
EnvironmentVariables = {
"CFFIXED_USER_HOME" = "/private/var/mobile/Applications/B9284FBE-E558-4A65-A7E4-AE20CDAD9A1D";
HOME = "/private/var/mobile/Applications/B9284FBE-E558-4A65-A7E4-AE20CDAD9A1D";
TMPDIR = "/private/var/mobile/Applications/B9284FBE-E558-4A65-A7E4-AE20CDAD9A1D/tmp";
};
IsUpgradeable = 1;
LSRequiresIPhoneOS = 1;
MinimumOSVersion = "5.0";
Path = "/private/var/mobile/Applications/B9284FBE-E558-4A65-A7E4-AE20CDAD9A1D/ZillowMap.app";
SequenceNumber = 2618;
SignerIdentity = "Apple iPhone OS Application Signing";
UIDeviceFamily = (
1,
2
);
UIPrerenderedIcon = 1;
};
此文件已在iOS 8中删除:(https://www.theiphonewiki.com/wiki/Com.apple.mobile.installation.plist)
在/var/mobile/Library/MobileInstallation/LastLaunchServicesMap.plist
处存在类似的iOS 8文件,但它可能只在启动时重新启动(重启)。
答案 1 :(得分:1)
如果您的代码在SpringBoard中运行,那么这是另一种解决方案:
NSString *applicationBundleIdentifier = @"...";
SBApplication *application = [[SBApplicationController sharedInstance]applicationWithDisplayIdentifier:applicationBundleIdentifier];
NSString *path = application.containerPath;
答案 2 :(得分:0)
如果您不介意卸载并重新安装目标应用程序,则更快捷的方法是卸载并重新安装目标应用程序。然后它将是应用程序容器或数据容器中的最新应用程序(现在分别是 /private/var/containers/Bundle/Application
和 /private/var/mobile/Containers/Data/Application
),您可以使用 ls
轻松找到,例如 {{1 }}。