I am having some strange problem.
I cant read plist file from application mainbundle
the file is in the "copy bundle resource"
but somehow it can not be read
here is the code
NSLog(@"%@",[[NSBundle mainBundle] pathForResource:@"8chk" ofType:@"plist"]);
it prints (null) all the time
here is the screenshot
can anyone tell me what is going on?
恐怕要说的是,您没有将此8chk.plist
添加到目标中。
Drag and drop plist file again in project, make sure you tick on checkbox while adding file to project which is saying "copy file in ProjectName"
then use this code to make it accessible and read values from plist
NSString *path = [[NSBundle mainBundle] pathForResource: @"YourPLIST" ofType: @"plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile: path];
[id obj = [dict objectForKey: @"YourKey"];
OR
// Reads the value of the custom key you added to the Info.plist
NSString *value = [mainBundle objectForInfoDictionaryKey:@"key"];
//Log the value
NSLog(@"Value = %@", value);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Info.plist"];
This might work. make sure to copy the plist to target and put it in root directory.also u can try to put the plist files where the apps default plist is kept.
:)
嗨Shoeb Amin,请检查您的plist文件是否已在Target-> Copy Bundle资源中添加
Your path is wrong. copy bundle resource
should read just 8chk.plist
, not 8chk.plist ..in resources/8chk
if the project navigator shows the correct tree.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.