你如何在 iOS 中调试发布模式构建的问题?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14460281/
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
How do you debug an issue with a release mode build in iOS?
提问by lehn0058
I am working on an iOS app and I have noticed a bug that is only reproducible when the app is built in release mode. The only way I have found to run a release mode app that I have built is by building an archive, signing it with my debug profile, and doing an ad-hoc deployment to my device. Using this method however I can't attach with a debugger, and I'm not even sure if I could attach it if it would work well after the release build had run the optimizer on the code.
我正在开发一个 iOS 应用程序,我注意到一个错误,只有当应用程序在发布模式下构建时才能重现。我发现运行我构建的发布模式应用程序的唯一方法是构建存档,使用我的调试配置文件对其进行签名,然后对我的设备进行临时部署。但是,使用这种方法我无法附加调试器,我什至不确定是否可以附加它,如果发布版本在代码上运行优化器后它可以正常工作。
Does anyone know of a good way to debug an issue that is only reproducible when an app is build in release mode?
有没有人知道一种调试问题的好方法,该问题仅在应用程序以发布模式构建时才可重现?
回答by Paul R
Normally Debug builds have optimisation disabled (-O0
) to make debugging easier, whereas Release builds have optimisation enabled (-O3
or -Os
), which makes the code run much faster, but also makes debugging harder (but not impossible). You can just go into the build settings in Xcode in the Debug configuration and temporarily turn up the optimisation level - this will keep all the other debug goodies (symbols etc) but hopefully also flush out the Release mode bug. (Don't forget to reset the optimisation level to -O0
in the Debug configuration when you're done!)
通常,Debug 版本禁用优化 ( -O0
) 以使调试更容易,而 Release 版本启用优化 (-O3
或-Os
),这使代码运行得更快,但也使调试更加困难(但并非不可能)。您可以在 Debug 配置中进入 Xcode 中的构建设置并暂时调高优化级别 - 这将保留所有其他调试功能(符号等),但希望也能清除发布模式错误。(完成后不要忘记-O0
在调试配置中将优化级别重置为!)
回答by Rahul Wakade
- Go to "Project" command in an Xcode application menu and chose "Edit Scheme"(Shortcut: ?< )
- Select "Run Project name" in left pane
- In right pane, under "Info" tab change "Build Configuration" to "Release"
- 转到 Xcode 应用程序菜单中的“项目”命令并选择“编辑方案”(快捷方式: ?< )
- 在左窗格中选择“运行项目名称”
- 在右窗格中,在“信息”选项卡下将“构建配置”更改为“发布”
回答by ehrpaulhardt
You can not run an app in release mode while have having debugging turned on. That is not intended.
打开调试后,您无法在发布模式下运行应用程序。这不是故意的。
When running an app in release mode you have to find a different way to observe the behaviour of your app (e.g. using alerts).
在发布模式下运行应用程序时,您必须找到一种不同的方式来观察应用程序的行为(例如使用警报)。
Additionally you will have to trust the distribution profile on your device. Xcode will notify and guide you with an alert message on the first run.
此外,您必须信任设备上的分发配置文件。Xcode 将在第一次运行时通过警告消息通知并指导您。
回答by Naveen Kumar
To debug an iOS application in release mode modify the settings: Build Settings -> Deployment -> Deployment Post Processing -> Release -> set value as "NO"
要在发布模式下调试 iOS 应用程序,请修改设置:构建设置 -> 部署 -> 部署后处理 -> 发布 -> 将值设置为“NO”
回答by Eric Wiener
I had to briefly turn on automatic signing in order to accomplish this. You aren't able to build directly on device with an iOS Distribution certificate (you need an iOS Development certificate) and you can't release to the App Store with an iOS Development certificate (you need an iOS Distribution certificate).
为了实现这一点,我不得不短暂地打开自动签名。您无法使用 iOS 分发证书(您需要 iOS 开发证书)直接在设备上进行构建,并且您无法使用 iOS 开发证书(您需要 iOS 分发证书)发布到 App Store。
My debug mode was configured to use an iOS Development certificate to build directly on device. My release mode was configured to use an iOS Distribution certificate to allow the app to be installed on all devices. In order to run in release mode on device I switched to automatic code signing briefly to test. Once I was done testing, I used git to revert to the previous Xcode configuration.
我的调试模式配置为使用 iOS 开发证书直接在设备上构建。我的发布模式配置为使用 iOS 分发证书,以允许在所有设备上安装该应用程序。为了在设备上以发布模式运行,我简要地切换到自动代码签名进行测试。完成测试后,我使用 git 恢复到以前的 Xcode 配置。
Not the most elegant way, but it got the job done.
不是最优雅的方式,但它完成了工作。