Xcode - 在设备上运行之前删除应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15258777/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:54:57  来源:igfitidea点击:

Xcode - Delete application before running on device

iosiphonexcode

提问by giorashc

Is there a way in Xcode (4.6) to delete the application on the device before installing it ?

Xcode (4.6) 有没有办法在安装之前删除设备上的应用程序?

I need it for testing purposes and it will be easier if the application will be deleted from the device before being installed again.

我需要它用于测试目的,如果在再次安装之前从设备中删除应用程序会更容易。

采纳答案by HackyStack

The only way is to delete it manually. There's no way to have xcode delete the app from a device before running each time if that's what you were asking. Sorry, it would be a great feature, but for now, there's no way to do that. Not even on the simulator.

唯一的方法是手动删除它。如果这是您的要求,则无法让 xcode 在每次运行之前从设备中删除该应用程序。抱歉,这将是一个很棒的功能,但目前还没有办法做到这一点。甚至在模拟器上也不行。

I think you should file a bug/feature request with apple though! That functionality would come in handy for me!

我认为您应该向苹果提交错误/功能请求!该功能对我来说会派上用场!

回答by user2010496

Yes you can.

是的你可以。

Get https://github.com/libimobiledevice/ideviceinstaller

获取https://github.com/libimobiledevice/ideviceinstaller

Which brings you the ability to use ideviceinstaller --uninstall <app-id>in the bash environment.

这为您带来了ideviceinstaller --uninstall <app-id>在 bash 环境中使用的能力。

Then do a script in your build configuration in xcode, such as: http://www.runscriptbuildphase.com/

然后在 xcode 的构建配置中做一个脚本,例如:http://www.runscriptbuildphase.com/

回答by Macistador

XCode don't offer an option for automatically removing the app from the device each time you run it, but the easy way is to use the 'Device' screen to remove it in one click.

XCode 不提供每次运行时自动从设备中删除应用程序的选项,但简单的方法是使用“设备”屏幕一键删除它。

Link to the Apple documentation

链接到 Apple 文档

回答by nevan king

How about creating an Xcode build script to quit the Simulator, then delete the contents of the Simulator Applications directory. The directory is

如何创建一个 Xcode 构建脚本来退出模拟器,然后删除模拟器应用程序目录的内容。目录是

~/Library/Application Support/iPhone Simulator/6.1/Applications/

回答by Krin-San

No, there is no way to delete app automatically.

不,没有办法自动删除应用程序。

But you can write a simple function to clean all app resources from the last run like this:

但是您可以编写一个简单的函数来清除上次运行中的所有应用程序资源,如下所示:

- (void)cleanUp {
    NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
    [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];

    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *context) {
        [[NSManagedObjectModel MR_defaultManagedObjectModel].entities enumerateObjectsUsingBlock:^(NSEntityDescription *entityDescription, NSUInteger idx, BOOL *stop) {
            [NSClassFromString([entityDescription managedObjectClassName]) MR_truncateAllInContext:context];
        }];
    }];
}

回答by Mike M

Like HackyStack, I think you have to delete the app manually. That said, you could have a debug startup method that clears the content that isn't overwritten during installation. for example, a method that removes the contents of the documents directory, keychain items associated with the app, iCloud KV info and documents, etc. It would be kind of a pain, but might get you where you want to go....

像 HackyStack 一样,我认为您必须手动删除该应用程序。也就是说,您可以使用调试启动方法来清除安装过程中未被覆盖的内容。例如,一种删除文档目录内容、与应用程序关联的钥匙串项目、iCloud KV 信息和文档等的方法。这会有点痛苦,但可能会让你到达你想去的地方......

回答by norbDEV

Working solution With macOS 10.15.2, Xcode11.3, iOS13.3 (iPhone XS), iOS12.4.4 (iPhone 5S)

适用于 macOS 10.15.2、Xcode11.3、iOS13.3 (iPhone XS)、iOS12.4.4 (iPhone 5S) 的解决方案

  • install: brew install mobiledevice (https://github.com/imkira/mobiledevice)
  • restart macOS
  • create/clone a Scheme
  • add this line in the Run/Pre-action: mobiledevice uninstall_app com.example.bundleid
  • 安装: brew install mobiledevice ( https://github.com/imkira/mobiledevice)
  • 重启 macOS
  • 创建/克隆一个方案
  • 在 Run/Pre-action 中添加这一行:mobiledevice uninstall_app com.example.bundleid