我尝试编写一个应用程序,它可以从 Web 服务器(ipa 文件)下载应用程序并安装。有人知道如何安装这个 ipa 文件吗?我可以在应用程序中使用 OTA 还是使用命令行安装它?
我尝试编写一个应用程序,它可以从 Web 服务器(ipa 文件)下载应用程序并安装。有人知道如何安装这个 ipa 文件吗?我可以在应用程序中使用 OTA 还是使用命令行安装它?
以下是针对越狱设备的即时解决方案,可以直接从应用程序中安装任何.ipa
文件。您需要执行以下步骤:
I. 获得root访问权限。您可以通过在main()
函数中调用setuid(0);
来实现。您需要在可执行文件上设置粘性权限位并使用启动脚本。
II. 解压.ipa
文件。没错,IPA只是伪装成ZIP文件。您可以使用开源的libzip库进行此操作。
III. 在其中有一个名为Payload
的目录。实际的应用程序包(我们称其为MyApp.app
)将驻留在该文件夹中。
IV. 在文件系统的/var/mobile/Applications
目录中创建一个目录。这将是要安装的应用程序的容器沙盒。按照惯例,此目录的名称应为UUID。例如,您可以使用以下代码片段:
CFUUIDRef uuidObj = CFUUIDCreate(NULL);
CFStringRef uuid = CFUUIDCreateString(NULL, uuidObj);
CFRelease(uuidObj);
NSString *appPath = [@"/var/mobile/Applications" stringByAppendingPathComponent:(id)uuid];
[fmgr createDirectoryAtPath:appPath withIntermediateDirectories:YES attributes:nil error:NULL];
CFRelease(uuid);
V. 通过循环遍历在步骤 II 获取的 Payload
目录的内容,找到应用程序包并将其复制到新创建的沙盒中(其名称为 UUID 字符串)。同时复制 iTunesMetadata.plist
和 iTunesArtwork
文件,以便 iTunes 显示一个漂亮的图标和通知您有更新。还要修复应用程序的可执行文件的权限,使其可以执行:
NSString *execName = [appInfoPlist objectForKey:@"CFBundleExecutable"];
NSString *execPath = [bundle stringByAppendingPathComponent:execName];
chmod(execPath.UTF8String, 0755);
VI. 您需要告诉SpringBoard定位您的应用程序,然后重新加载其已安装的应用程序缓存,以使新安装的图标出现在主屏幕上。为此,首先更新MobileInstallation属性列表文件中应用程序列表。这里的 bundle
变量指的是应用包的文件系统位置,类似于 /var/mobile/applications/LONG_UUID_STRING/MyApp.app
。
#define kMobileInstallationPlistPath @"/var/mobile/Library/Caches/com.apple.mobile.installation.plist"
NSMutableDictionary *appInfoPlist = [NSMutableDictionary dictionaryWithContentsOfFile:[bundle stringByAppendingPathComponent:@"Info.plist"]];
[appInfoPlist setObject:@"User" forKey:@"ApplicationType"];
[appInfoPlist setObject:bundle forKey:@"Path"];
[appInfoPlist setObject:@{
@"CFFIXED_USER_HOME" : appPath,
@"HOME" : appPath,
@"TMPDIR" : [appPath stringByAppendingPathComponent:@"tmp"]
} forKey:@"EnvironmentVariables"];
[appInfoPlist setObject:appPath forKey:@"Container"];
NSData *data = [NSData dataWithContentsOfFile:kMobileInstallationPlistPath];
NSMutableDictionary *mobileInstallation = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListMutableContainersAndLeaves format:NULL error:NULL];
NSString *bundleID = [appInfoPlist objectForKey:@"CFBundleIdentifier"];
[[mobileInstallation objectForKey:@"User"] setObject:appInfoPlist forKey:bundleID];
[mobileInstallation writeToFile:kMobileInstallationPlistPath atomically:NO];
然后删除SpringBoard存储的缓存应用程序信息:
remove("/var/mobile/Library/Caches/com.apple.mobile.installation.plist");
remove("/var/mobile/Library/Caches/com.apple.springboard-imagecache-icons");
remove("/var/mobile/Library/Caches/com.apple.springboard-imagecache-icons.plist");
remove("/var/mobile/Library/Caches/com.apple.springboard-imagecache-smallicons");
remove("/var/mobile/Library/Caches/com.apple.springboard-imagecache-smallicons.plist");
remove("/var/mobile/Library/Caches/SpringBoardIconCache");
remove("/var/mobile/Library/Caches/SpringBoardIconCache-small");
remove("/var/mobile/Library/Caches/com.apple.IconsCache");
Class __LSApplicationWorkspace = objc_getClass("LSApplicationWorkspace");
[(LSApplicationWorkspace *)[__LSApplicationWorkspace defaultWorkspace] invalidateIconCache:nil];
[(LSApplicationWorkspace *)[__LSApplicationWorkspace defaultWorkspace] registerApplication:[NSURL fileURLWithPath:bundle]];
notify_post("com.apple.mobile.application_installed");