开发者

Using file as input, iPhone App

开发者 https://www.devze.com 2022-12-12 10:04 出处:网络
I have iPhone Library in c (it is created from c source in MAC). There is a method that read a file using file path. Now I want to input the file path in Objective-C to that method. My questions are:

I have iPhone Library in c (it is created from c source in MAC). There is a method that read a file using file path. Now I want to input the file path in Objective-C to that method. My questions are:

  • Is it possible to do? I mean use c library to read file on iPhone.

if it is possible,

  • Where is the location in my project to put the file? (Resources ?)
  • And, how can I get the path to be 开发者_如何学Pythoninput in the method? (NSBundle ?)

Thanks


Can't really answer you first question, cause I don't know the answer.

But for the second file, the best location is the documents directory. To get the path of a file:

NSString* myPath = [[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"plist"];

Or in a specific directory:

NSArray *myPathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *myDirectory = [myPathArray objectAtIndex:0];
    NSString *myPath = [myDirectory stringByAppendingPathComponent:@"myFile.plist"];

Hope that answered your question.

Regards, Paul Peelen


Yes, you can use static C libraries on the iPhone, unless they have dependencies that cannot be resolved. Objective-C is a superset of C, so you can just code in C and use your library this way and it will compile just fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消