我正在尝试做什么:
NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSApplicationSupportDirectory,NSUserDomainMask,YES);Nsstring *pListPath = [[paths lastObject] stringByAppendingPathComponent:@“somedata.pList”];if(pListData) { NSLog(@"PATH: %@",pListPath); BOol success = [pListData writetofile:pListPath atomically:YES]; NSLog(@"SUCCESS: %hhd",success);}else { NSLog(@"ERROR CREATING PList: %@",error);}
而我输出NO:
PATH: /var/mobile/Applications/40954....7E3C/library/Application Support/somedata.pListSUCCESS: 0
Apple文档说:
Use the Application Support directory constant NSApplicationSupportDirectory,appending your <bundle_ID> for: …
什么意思附加你的bundle_ID?可能还有另一条路我应该用? NSdocumentDirectory不适合我,因为它是用户文件的位置.
解决方法 存储到NSApplicationSupportDirectory有点复杂,按照此Apple sample code将文件写入此目录,
- (NSURL*)applicationDirectory{ Nsstring* bundleID = [[NSBundle mainBundle] bundleIDentifIEr]; NSfileManager*fm = [NSfileManager defaultManager]; NSURL* dirPath = nil; // Find the application support directory in the home directory. NSArray* appSupportDir = [fm URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask]; if ([appSupportDir count] > 0) { // Append the bundle ID to the URL for the // Application Support directory dirPath = [[appSupportDir objectAtIndex:0] URLByAppendingPathComponent:bundleID]; //ModifIEd code to write your pList file to the Application support dir Nsstring *pListPath = [dirPath stringByAppendingPathComponent:@“somedata.pList”]; //Assuming pListData is pre-populated ivar //Else add your code to create pListData here if(pListData) { BOol success = [pListData writetofile:pListPath atomically:YES]; NSLog(@"SUCCESS: %hhd",success); } else { NSLog(@"ERROR CREATING PList: %@",error); } }}总结
以上是内存溢出为你收集整理的ios – 附加您的目录.它是什么?全部内容,希望文章能够帮你解决ios – 附加您的目录.它是什么?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)