如何在IOS Action App Extension中调试JavaScript? [英] How to debug JavaScript in IOS Action App Extension?

查看:68
本文介绍了如何在IOS Action App Extension中调试JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用iOS, Action App Extension ,可以针对HTML运行JavaScript代码。但是,经过对谷歌的一些搜索后,我还没有找到任何解释如何在这种情况下进行调试的文档(插入一个断点或只是添加/查看控制台out语句)。

With iOS, Action App Extension, one could run a JavaScript code against HTML. However, after quite some search on Google, I have not found any document explaining how to debug in this situation (insert a break point or simply add/view console out statement).

推荐答案

虽然最近我遇到了连接到模拟器时出现的页面问题,但这并不太难。在那种情况下,我最终直接使用了我的手机。 (显然你需要在iOS模拟器开始检查远程模拟器会话后启动桌面Safari)

It's not too hard, although recently I've had an issue with the page showing up when connected to the simulator. In that case I just ended up using my phone directly. (Apparently you need to start desktop Safari after the iOS Simulator has started to inspect "remote" Simulator sessions)


  • 确保在设备上设置 - > Safari->高级 - >网络检查器已开启

  • (确保您信任计算机来自设备)

  • 通过从Xcode运行并选择Safari
    来启动设备上的MobileSafari - 这不是必需的,但您可以解码iOS Objective-C / Swift代码也是如此。您可以手动启动MobileSafari,它将在桌面Safari中显示。

  • Ensure that on the device Settings->Safari->Advanced->Web Inspector is on
  • (Make sure you've Trusted the computer from the device)
  • Start MobileSafari on your device by running from Xcode and choosing Safari -- this isn't necessary but you can decode the iOS Objective-C/Swift code as well. You can just start MobileSafari manually and it will be visible in desktop Safari.

在桌面上启动Safari,确保 Show Develop菜单在菜单栏中首选项中打开。

Start Safari on your desktop, make sure Show Develop menu in menu bar is on in Preferences.

您现在正在桌面上调试该设备页面。

You are now debugging that device page on your desktop.

有自动启动调试器等...的选项,但我发现当我尝试这些时,我的代码将无法执行。

There are options to 'Automatically start debugger etc...', but I've found that when I tried these my code would not execute.

您不能将调试器语句放在应用程序扩展JavaScript中,因为在您的App Extension启动之前它不会被注入。相反,我会将调试器; 语句添加到我的应用扩展程序JavaScript代码中,该代码将在调试器的应用程序扩展JavaScript代码中暂停调试器; 声明。

You can't place debugger statements in the app extension JavaScript as it isn't injected until your App Extension starts. Instead I would add a debugger; statement to my app extension JavaScript code which will pause the debugger in the app extension JavaScript code at the debugger; statement.

通过在分享菜单中选择它来启动您的应用扩展程序,设置您感兴趣的任何其他断点,然后点击调试器上的继续按钮。

Start your app extension by selecting it in the Share menu, set any other breakpoints you are interested in, then hit the continue button on the debugger.

当然,你也会捕获未捕获的异常。

You will also catch uncaught exceptions of course.

官方文档为此,此处

确保从生产代码中删除调试器; 行。

Make sure you remove the debugger; line from production code.

这篇关于如何在IOS Action App Extension中调试JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆