Debugging Quicklook Plugin in Xcode 4.6

南笙酒味 提交于 2019-11-28 22:04:52
Mikhail Grebionkin

You can use brake points and NSLog function for debugging QL plugin. But first you need to configure environment.

  • Select your project on Project Navigator
  • Then select QL plugin target
  • Go to 'Build Phases' tab and add new phase 'Copy files'
  • Select 'Absolute Path' on destination drop down menu and set ~/Library/QuickLook as subpath
  • Open terminal and copy qlmanage to your project's root directory with command cp /usr/bin/qlmanage PROJECT_ROOT_DIR
  • Then select menu Product -> Scheme -> Edit Scheme...
  • Select 'Run' on schemes list
  • On info tab select executable drop down menu, then 'Other...' and select qlmanage binary you have copied to project's root directory
  • On arguments tab add row for 'Arguments Passed On Launch' and set value to -p FULL_PATH_TO_FILE_FOR_PREVIEW

After all steps you can run your project and debug your code.

Xcode 6 must be different somehow, because the instructions above didn't work for me. But here's a solution that I puzzled out today and that works. Hopefuly it will help someone else.

(Assume the name of your plugin is myplugin.qlgenerator)

First of all, if you tried the earlier solutions above, undo them.

  1. Delete the Copy Phase that copies your binary to ~/Library/Quicklook and delete the copy of qlmanage you may have copied to your project's root.

Set the Executable to /usr/bin/qlmanage. "qlmanage" is the program that will load and run your plugin.

  1. Edit your scheme.

  2. Choose 'Run' from the list on the left, then the Info tab of the display on the right.

  3. Choose 'Other...' from the Executable popup. A standard file sheet will appear.

  4. Type cmd-shift-g. A 'Go to folder' sheet appears with a text field.

  5. Enter /usr/bin/ and hit the Go button. The standard file sheet should now be showing the contents of /usr/bin.

  6. Select the 'qlmanage' binary

  7. Turn on the 'Debug executable' checkbox and click the Choose button.

Configure the Arguments Xcode passes to qlmanage

  1. Select the Arguments tab in the Run section of the Edit Schemes sheet.

  2. Remove any arguments that may be left over from previous attempts.

  3. Add -c public.data as the first argument to be passed on launch. You may need to change this depending on the kind of UTIs your plugin supports.

  4. Add -g $(BUILD_DIR)/Debug/myplugin.qlgenerator as the second argument. This resolves to a path to the debug version of your plugin.

  5. Add -p '/fullpath/to/file/to/be/quicklooked as the third argument. This is a path to a file that should already exist. Your plugin will be asked to render previews of this file.

  6. Close the Schemes sheet.

That's it. You should now be able to debug your pluging including setting (and hitting) breakpoints!

Gavin Maclean

I've written this blog post describing how to debug Quick Look plugins which should work as of Xcode 8.2 / macOS 10.12.

Giving due credit, this is basically the steps given here by mlist0987 but with an extra step to get around the System Integrity Protection introduced in 10.11.

TLDR: you have to take a copy of the version of qlmanage, referenced by the link in /usr/bin (i.e. don't just copy the alias) and set that as the debugging executable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!