简体   繁体   English

在iOS项目中包括需要外部文件的库

[英]Including libraries that need external files in iOS project

There are some 3rd party in my code, like the World Magnetic Model or GeoTrans. 我的代码中有一些第三方,例如世界电磁模型或GeoTrans。 Both read in files from the current directory when compiled as command line binaries, which is no problem. 当编译为命令行二进制文件时,两者都从当前目录中读取文件,这没有问题。 However, when I include that code in my iOS project, for some reason I have trouble making that work. 但是,当我在iOS项目中包含该代码时,由于某种原因,我无法使其正常工作。

In the 3rd Party code, the file is read with fopen, like: 在第三方代码中,使用fopen读取文件,例如:

MODELFILE = fopen(filename, "r");

where filename is something like "wmm.cof" and MODELFILE ends up being NULL (0x0). 其中,文件名类似于“ wmm.cof”,而MODELFILE最终为NULL(0x0)。

When I check my app bundle, I do see a file called wmm.cof in the same (root) directory as the binary of my app, but no luck. 当我检查应用程序捆绑包时,确实在与应用程序的二进制文件相同的(根)目录中看到一个名为wmm.cof的文件,但没有运气。

How can I handle that? 我该如何处理?

Thanks! 谢谢!

you want to do something like: 您想要做类似的事情:

NSString *path = [[NSBundle mainBundle] pathForResource:@"wmm" ofType:@"cof"];
MODELFILE = fopen([path cStringUsingEncoding:NSUTF8StringEncoding], "r");

if you want to keep the file that code is in portable, you may want to move the objc code to a separate file and just return a const char * 如果要保留代码可移植的文件,则可能需要将objc代码移动到单独的文件中,然后只返回const char *

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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