如何将数据从Web更新到iphone的现有文件

时间:2010-08-10 09:31:53

标签: iphone

 NSString *applicationDocumentsDir = 
         [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
         NSString *storePath = [applicationDocumentsDir stringByAppendingPathComponent:@"sample1.cfg"];

         NSURL  *instructionsURLd = [[NSURL alloc] initFileURLWithPath:filePath];
         NSData *dataXML = [NSData dataWithContentsOfURL:instructionsURLd];

         [dataXML writeToFile:storePath  atomically:YES];

         NSLog(@"matrix  path  %@",applicationDocumentsDir);
         NSLog(@"neo path  %@",storePath);

使用此我可以立即将数据从我的应用程序保存到Documents文件夹 sample1.cfg 现在有10个数据我想在用户点击更新按钮时从网上再添加10个? 所以如何添加10个数据plz帮助

由于

1 个答案:

答案 0 :(得分:0)

...
NSData *dataXML = [NSData dataWithContentsOfURL:instructionsURLd];
NSMutableData *file = [[NSMutableData alloc] initWithContentsOfFile:storePath];
[file appendData:dataXML];
[file writeToFile:storePath atomically:YES];
...

这将附加dataXML。如果要预先添加数据,请使用:

...
NSMutableData *dataXML = [[NSData dataWithContentsOfURL:instructionsURLd] mutableCopy];
NSData *file = [[NSData alloc] initWithContentsOfFile:storePath];
[dataXML appendData:file];
[dataXML writeToFile:storePath atomically:YES];
...