IOS plist与沙盒的初步使用
2014-06-23 16:36
148 查看
一般情况下是不能对工程目录下的plist文件进行写操作的。
可以通过沙盒机制,我们直接在程序目录下读写操作。
/*/读取plistNSMutableDictionary *dic=[NSMutableDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"TKHttpBaseInfo" ofType:@"plist"]];NSLog(@"%@",dic);//修改内容[dic setObject:userName forKey:@"userName"];[dic setObject:password forKey:@"passwordKey"];[dic setObject:apikey forKey:@"apiKey"];//获取应用程序沙盒的Documents目录NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);NSString *path = [paths objectAtIndex:0];//得到完整的文件名NSString *filename=[path stringByAppendingPathComponent:@"TKHttpBaseInfo.plist"];[dic writeToFile:filename atomically:YES];NSLog(@"%@",dic);*/NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]stringByAppendingPathComponent:@"TKHttpBaseInfo.plist"];NSFileManager *fm = [[NSFileManager alloc]init];//[fm createFileAtPath:path contents:nil attributes:nil];if (![fm fileExistsAtPath:path]) {if(![fm createFileAtPath:path contents:nil attributes:nil]){NSLog(@"create file error");}else{//NSMutableDictionary *dic = [[[NSMutableDictionary alloc]initWithContentsOfFile:path]mutableCopy];NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:3];[dic setObject:userName forKey:@"userName"];[dic setObject:password forKey:@"passwordKey"];[dic setObject:apikey forKey:@"apiKey"];[dic writeToFile:path atomically:YES];NSLog(@"000---------->>>%@",dic);}}else{NSMutableDictionary *dic = [[NSMutableDictionary alloc]initWithContentsOfFile:path];[dic setObject:userName forKey:@"userName"];[dic setObject:password forKey:@"passwordKey"];[dic setObject:apikey forKey:@"apiKey"];[dic writeToFile:path atomically:YES];NSLog(@"111---------->>>%@",dic);}
相关文章推荐
- 程序中的文件之沙盒以及plist文件的初步使用
- 程序中的文件之沙盒以及plist文件的初步使用
- 【详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!】【二】
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!
- 详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!【2012-6-25日更新iap恢复详解】
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!【2012-6-25日更新iap恢复详解】
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!【2012-12-11日更新获取"产品付费数量等于0的问题"】
- 详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!2012-6-25日更新iap恢复
- 详解iOS应用程序内使用IAP/StoreKit付费,沙盒(SandBox)测试,创建测试账号流程
- 【详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!】【一】(转载)
- iOS 开发之 PList 的使用
- Himi 原创 详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!
- 详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!
- ios 应用内支付,沙盒测试时出现“此Apple ID尚未在iTunes Store使用过。。。”
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!
- iOS-Cocos2d游戏开发】使用plist文件制作简单精灵
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!2012-6-25日更新iap恢复