OS X 上插件中资源文件夹的路径
我正在为 OS X 编写 FileMaker Pro 插件,并且需要能够访问 /Applications/FileMaker Pro 11/Extensions/blah.fmplugin/Contents/Resources
目录中的文件。 (但这可能是 /apps/FileMaker Pro 11 Advanced/Extensions/xyz.fmplugin/Contents/Resources
或其他内容,具体取决于用户安装 FMP 的位置以及他们是否重命名插件等。)我无法控制用户安装 FMP 的位置,或者他们是否运行 FMP 或 FMPA,或者他们是否重命名了我的插件(尽管这比 FMP 与 FMPA 情况不太可能),我不 了解插件包的路径。
我找到了这样的答案: 相对路径在 Xcode C++ 中不起作用 但这为我提供了 FileMaker.app 中的 Resources 文件夹的路径,而不是我的插件中的路径。
即我得到 /Applications/FileMaker Pro 11/FileMaker Pro.app/Contents/Resources
而不是我的插件中的 Resources 文件夹的路径。
我需要在 Xcode 中配置一些东西才能使上述解决方案起作用吗?或者还有其他方法可以到达该路径吗? CFBundleGetMainBundle() 调用听起来像是要返回应用程序本身的包而不是插件。
我根据 Bundle 编程指南和 CFBundleGetBundleWithIdentifier (由 mipadi 提到)找到了一些可能性,但我还无法确切地弄清楚我需要什么功能以及先决条件是什么。
I'm writing a FileMaker Pro plugin for OS X, and I need to be able to access a file in the /Applications/FileMaker Pro 11/Extensions/blah.fmplugin/Contents/Resources
directory. (But this could be /apps/FileMaker Pro 11 Advanced/Extensions/xyz.fmplugin/Contents/Resources
or something else, depending on where the user installed FMP and whether they renamed the plugin etc.) Since I can't control where the user has installed FMP, or whether they are running FMP or FMPA or whether they have renamed my plugin (although this is less likely than the FMP vs FMPA situation), I do not know the path to the plugin's bundle.
I've found answers like this: Relative Paths Not Working in Xcode C++ but that gives me the path to the Resources folder in the FileMaker.app instead of in my plugin.
i.e. I get /Applications/FileMaker Pro 11/FileMaker Pro.app/Contents/Resources
instead of the path to the Resources folder in my plugin.
Is there something I need to configure in Xcode to get the above solution to work? Or is there some other way to get at the path? The CFBundleGetMainBundle() call makes it sound like it is meant to return the bundle of the app itself rather than the plugin.
I have found some possibilities based on the Bundle Programming Guide and CFBundleGetBundleWithIdentifier (mentioned by mipadi), but I haven't been able to figure out yet exactly what functions I need and what the prerequisites are.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎可以做到。 CFBundleGetBundleWithIdentifier 应该也可以工作,但我决定使用 NSBundle 的东西而不是 CF*。我将其放入 .mm 文件中并将其包含在项目中。然后我可以调用 get_resources_path() 函数并获取字符串形式的路径。
This seems to do it. CFBundleGetBundleWithIdentifier should have worked too, but I decided to go with the NSBundle stuff rather than CF*. I put this in a .mm file and included it in the project. I can then call the get_resources_path() function and get the path as a string.
您可以使用
CFBundleCreate
(如果您知道捆绑包的路径);或者您可以通过 CFBundleGetBundleWithIdentifier 使用包标识符获取包。You can use
CFBundleCreate
if you know the path to your bundle; or you can get the bundle using the bundle identifier viaCFBundleGetBundleWithIdentifier
.