开发者

How to access files in interior of an iPhone App?

开发者 https://www.devze.com 2022-12-28 12:49 出处:网络
I need in a iPhone app to access files that the app is build with(.plist etc). There\'s an hardcoded way to do this:

I need in a iPhone app to access files that the app is build with(.plist etc). There's an hardcoded way to do this:

NSString *appDir = [[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
                      objectAtIndex:0] 
                     stringByDeletingLastPathComponent]
                    stringByAppendingPathComponent:appFolder];

where appFolder is the name o开发者_StackOverflow中文版f folder app, like "test.app". After the appDir is known, to access files is simple.

Is there any other, not-hardcoded way to have access to files form the app?

Thanks in Advance!


 NSString* pathToFile = 
    [[[NSBundle mainBundle] resourcePath] 
         stringByAppendingPathComponent:@"myFile.plist"];

// or, even better (handling localization):
NSString* pathToFile = [[NSBundle mainBundle] pathForResource:@"myFile"
                                                       ofType:@"plist"];


Your app folder is the "main bundle". So you can use NSBundle methods such as

NSString* path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"plist"];
0

精彩评论

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