如何在我的swift应用程序中调试/测试URL打开?

时间:2021-04-29 07:20:05

I am trying to write an app in swift that can be opened with a custom URL scheme. I want to test this functionality by letting my app be launched by opening a URL. How do I debug this in Xcode? Is there a way to simulate URL launching in Xcode?

我正在尝试用swift编写一个应用程序,它可以使用自定义URL模式打开。我想通过打开一个URL来测试这个功能。如何在Xcode中调试这个?有办法在Xcode中模拟URL启动吗?

Edit: It's a macOS app.

编辑:这是一个macOS应用。

Here's my workaround: build the app, copy it into the applications folder so that it registers the URL scheme, open test URL from safari.

下面是我的解决方案:构建应用程序,将它复制到应用程序文件夹中,这样它就可以注册URL方案,从safari打开测试URL。

1 个解决方案

#1


1  

OK so after some time experimenting with debug schemes, I have an answer now. After registering the URL scheme in you info.plist, compile and make sure the app is able to be opened by a URL.

经过一段时间的调试方案实验,现在我有了答案。在您的信息中注册URL方案之后。plist,编译并确保应用程序可以通过URL打开。

Then go to "edit scheme" > info > "wait for executable to be launched" and then run it from Xcode. Now if you click a URL, your app will run with Xcode's debugger attached and your breakpoints will hit.

然后去“编辑scheme”> info >“等待可执行文件启动”,然后从Xcode中运行它。现在,如果您点击一个URL,您的应用程序将运行Xcode的调试器,您的断点将会被击中。

#1


1  

OK so after some time experimenting with debug schemes, I have an answer now. After registering the URL scheme in you info.plist, compile and make sure the app is able to be opened by a URL.

经过一段时间的调试方案实验,现在我有了答案。在您的信息中注册URL方案之后。plist,编译并确保应用程序可以通过URL打开。

Then go to "edit scheme" > info > "wait for executable to be launched" and then run it from Xcode. Now if you click a URL, your app will run with Xcode's debugger attached and your breakpoints will hit.

然后去“编辑scheme”> info >“等待可执行文件启动”,然后从Xcode中运行它。现在,如果您点击一个URL,您的应用程序将运行Xcode的调试器,您的断点将会被击中。