2011-05-14 30 views
1

此代码适用于模拟器,但不适用于设备。我肯定这有什么写作做文件:writeToFile在SIM卡中工作,但不在设备上

NSString *path = [[NSBundle mainBundle] pathForResource:@"SongData" ofType:@"plist"]; 
     NSArray *tempData = [[NSArray alloc] initWithContentsOfFile: path]; 

     NSMutableArray *arr = [[NSMutableArray alloc] init]; 
     for (NSDictionary *dict in tempData) { 
      NSMutableDictionary *new = [[dict mutableCopy] autorelease]; 
      if ([[new objectForKey:@"Song Title"] isEqualToString:[[tableData objectAtIndex:[indexPath row]] objectForKey:@"Song Title"]]) { 
       BOOL fav = [[new objectForKey:@"Favorite"] boolValue]; 
       [new setObject:[NSNumber numberWithBool:!fav] forKey:@"Favorite"]; 
      } 
      [arr addObject:new]; 
     } 
     [arr writeToFile:path atomically:YES]; 

我基本上写入文件的NSMutableArray里,我不知道是什么意思原子,但我试图既肯定又否定,既不要工作。

谢谢。

回答

3

由于沙箱限制(它也会破坏您的代码签名),您无法写入您的应用程序包。您应该写入应用程序的文档目录。

你可以让你的文件目录:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *docPath = [paths objectAtIndex:0]; 
+0

我想通了,但感谢。 – user635064 2011-05-15 00:34:21

相关问题