2010-12-14 112 views
1

我正在写的FileMaker Pro插件OS X,我需要能够访问一个文件中的/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已经重新命名了我的插件(虽然这比FMP vs FMPA的情况更不可能),我不知道插件的包的路径路径的资源文件夹中的插件在OS X

我找到的答案是这样的:Relative Paths Not Working in Xcode C++但给我的路径在FileMaker.app,而不是在我的插件资源文件夹。

即我得到/Applications/FileMaker Pro 11/FileMaker Pro.app/Contents/Resources,而不是在我的插件路径的资源文件夹。

有什么我需要在Xcode中获得上述解决方案的工作进行配置?或者有其他方法可以找到路径吗? CFBundleGetMainBundle()调用使得它听起来像是要返回应用程序本身的包而不是插件。

我发现了一些基于Bundle编程指南和CFBundleGetBundleWithIdentifier(由mipadi提到)的可能性,但是我还没有弄清楚我需要什么功能以及什么先决条件。

回答

3

这似乎是这样做的。 CFBundleGetBundleWithIdentifier也应该起作用,但我决定使用NSBundle而不是CF *。我把它放在一个.mm文件中,并将其包含在项目中。然后我可以调用get_resources_path()函数并以字符串形式获取路径。

#include <Foundation/Foundation.h> 

#include <string> 

std::string *get_resources_path() 
{ 
    NSBundle *bundle; 

    bundle = [NSBundle bundleWithIdentifier: @"com.example.fmplugin"]; 
    if (bundle == NULL) { 
     // error handling 
    } 

    NSString *respath = [bundle resourcePath]; 
    if (respath == NULL) { 
     // error handling 
    } 

    const char *path = [respath UTF8String]; 
    if (path == NULL) { 
     // error handling 
    } 

    return new std::string(path); 
} 
+0

这样的有用的解决方案。谢谢!! – Stan 2014-12-16 21:41:29

2

您可以使用CFBundleCreate如果你知道路径到您的包;或者您可以通过CFBundleGetBundleWithIdentifier使用捆绑标识符获取捆绑软件。

相关问题