xcode iOS:如何从 URL 调试“全新启动”应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18521276/
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 03:44:49  来源:igfitidea点击:

iOS: How to debug "freshly launching" an app from a URL

iosxcodedebuggingios-simulatoropenurl

提问by Chicowitz

When launching an app from a URL, there is a distinction between whether the URL is freshly launching an app, or if it's resuming an app that has been put into a suspended state.

从 URL 启动应用程序时,该 URL 是新启动应用程序还是正在恢复已置于暂停状态的应用程序之间存在区别。

My question is, how do I debug the process of a "fresh launch" froma URL? Hitting "Run" in Xcode automatically opens the app. Then, I have to suspend the app to reach Safari and access my test site. But if I close my suspended app, Xcode is no longer attached to it and I'm unable to debug.

我的问题是,如何URL调试“全新启动”的过程?在 Xcode 中点击“运行”会自动打开应用程序。然后,我必须暂停应用程序才能访问 Safari 并访问我的测试站点。但是如果我关闭我暂停的应用程序,Xcode 不再附加到它并且我无法调试。

回答by Lian van der Vyver

These steps can be followed on the device. Founded at this link.

可以在设备上执行这些步骤。在此链接上成立。

  1. Run the app from Xcode to install it on your device and then stop it from Xcode.
  2. Force quit the app from the app switcher UI on the device.
  3. Navigate to the scheme for the project in Xcode. Under the Run section's Info tab, there is a radio button for "Wait for executable to be launched". Make sure this is checked instead of the "Automatically" option.
  4. Run the app from Xcode. It will not open on the device, but the debugger will wait for it to open and then it will attach to it.
  1. 从 Xcode 运行应用程序以将其安装到您的设备上,然后从 Xcode 停止它。
  2. 从设备上的应用切换器 UI 强制退出应用。
  3. 在 Xcode 中导航到项目的方案。在“运行”部分的“信息”选项卡下,有一个“等待可执行文件启动”的单选按钮。确保选中此选项而不是“自动”选项。
  4. 从 Xcode 运行应用程序。它不会在设备上打开,但调试器会等待它打开,然后它会附加到它。

On the simulator as suggested by Marc-Alexandre Bérubé.

在 Marc-Alexandre Bérubé 建议的模拟器上。

  1. Run your app on the simulator.
  2. Force quit the app on the simulator. Press cmd+shift+(hit h twice). Swipe the app up.
  3. Open your terminal and enter this xcrun simctl openurl booted http://yourdomain/path.
  1. 在模拟器上运行您的应用程序。
  2. 强制退出模拟器上的应用程序。按cmd+shift+(hit h twice)。向上滑动应用程序。
  3. 打开你的终端并输入这个xcrun simctl openurl booted http://yourdomain/path

回答by arielyz

You need to configure your Xcode app scheme to wait for the app to be launched manually. Here is how you do it: http://blogmobile.itude.com/2013/09/03/how-to-debug-deep-linking-in-ios/.

您需要配置您的 Xcode 应用程序方案以等待应用程序手动启动。这是您的操作方法:http: //blogmobile.itude.com/2013/09/03/how-to-debug-deep-linking-in-ios/

You then need to copy the launch URL and paste it to Mobile Safari. This will launch your app, and make Xcode get attached to the running app process.

然后,您需要复制启动 URL 并将其粘贴到 Mobile Safari。这将启动您的应用程序,并使 Xcode 附加到正在运行的应用程序进程。

回答by nteissler

While the answers that mention activating "Wait for executable to be launched" are good in theory, for various reasons these didn't work for me. On the simulator, though Xcode claimed it had "attached", no logs or breakpoints were ever shown. On-device I was running iOS 13, building from Xcode 10, and using Xcode 11 to load, so I didn't have any debugging symbols. That was more of a personal problem, I suspect on device debugging may have worked.

虽然提到激活“等待可执行文件启动”的答案在理论上是好的,但由于各种原因,这些对我不起作用。在模拟器上,尽管 Xcode 声称它已“附加”,但从未显示任何日志或断点。在设备上,我运行的是 iOS 13,从 Xcode 10 构建,并使用 Xcode 11 加载,所以我没有任何调试符号。这更多是个人问题,我怀疑设备调试可能有效。

What worked best for me was just opening up Console.appon my mac, and using the OSLogAPIs to get a solid stream of caveman debugging from the simulator.

对我来说最有效的方法是在我的 mac 上打开Console.app,并使用OSLogAPI 从模拟器中获得稳定的穴居人调试流。

  1. Run the app from Xcode on the simulator.
  2. Then immediately quit it on the simulator via the app launched (Cmd-Shift-H * 2)
  3. Launch the app by tapping a deep link I sent to myself via the Messages app
  4. Observe my logs in Console.app
  1. 在模拟器上从 Xcode 运行应用程序。
  2. 然后立即通过启动的应用程序在模拟器上退出它(Cmd-Shift-H * 2)
  3. 通过点击我通过消息应用程序发送给自己的深层链接来启动应用程序
  4. 在 Console.app 中观察我的日志

It's not pretty, but it is highly reliable.

它并不漂亮,但非常可靠。

It's also worth mentioning, that you can protect this useful feature by testing cold start deep-linking via XCUITest. You can call app.terminatein your XCUITests, then open a deep link (typically via a static web page you've setup, I use public GitHub wikis for this) and write tests and assert behaviors just like normal.

还值得一提的是,您可以通过 XCUITest 测试冷启动深度链接来保护这个有用的功能。您可以调用app.terminate您的 XCUITests,然后打开一个深层链接(通常通过您设置的静态网页,我为此使用公共 GitHub wiki)并像往常一样编写测试和断言行为。