简体   繁体   中英

How to debug JavaScript in IOS Action App Extension?

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).

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)

  • 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.

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

  • In the Develop menu you will see your device name, say 'BSharer's iPhone'
  • select the page name underneath your device name, say 'en.m.wikipedia.org - Wikipedia'.

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.

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.

The official documentation for this is here .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM