如何使用非越狱设备的私有框架以编程方式删除iOS应用程序

问题描述:

我正在制作一个内部(企业)应用程序。我想以编程方式从iOS设备中删除其他已安装的应用。我已经使用Apple的私有框架方法成功检索了已安装的应用程序的信息(例如name,bundleId,version,icon等)。请告诉我该怎么做(即删除一个应用程序)。谢谢。

I am making an in-house (Enterprise) app. I want to delete other installed apps from the iOS device programmatically. I have successfully retrieved the installed apps' info (e.g. name, bundleId, version, icon etc.) using Apple's private framework methods. Please tell me how can I do that (i.e. delete an app). Thanks.

好吧@Salman表示

Well as @Salman indicated

这是一个解决方案(没有越狱没有崩溃),但它每次都不起作用。有时无法卸载应用程序并返回

Here is a solution (No jailbreak No crash) but its not working every time. Sometime it failed to uninstall application and return NO.

NSBundle *b = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/MobileCoreServices.framework"];
BOOL success = [b load];
if(success)
{
    Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");
    id si = [LSApplicationWorkspace valueForKey:@"defaultWorkspace"];

    SEL selector=NSSelectorFromString(@"uninstallApplication:withOptions:");
    BOOL what=[si performSelector:selector withObject:@"Bundle_ID" withObject:nil];
}