0

我已经看到 writeToFile 不适用于非对象的解释,但是,此片段显示在 iPad 设备上的工作原理和模拟器的工作原理之间存在严重差距。

NSMutableArray *arrayOne = [NSMutableArray arrayWithObjects:@"Thing One", @"Thing Two", @"Thing Three", nil];
[arrayOne writeToFile:@"myLocalMovieMetaData-v11" atomically:YES];
NSLog(@"cancelNowButton Test Metadata File Written.");  
NSMutableArray *arrayTwo = [NSMutableArray arrayWithContentsOfFile:@"myLocalMovieMetaData-v11"];
NSLog(@"arrayOne: %@",arrayOne);
NSLog(@"arrayTwo: %@",arrayTwo);  //this prints on simulator but not the device.
4

1 回答 1

3

该应用程序只有写入其 Documents 目录的权限:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myLocalMovieMetaData-v11"];

然后使用:

[arrayOne writeToFile:path atomically:YES];
于 2011-01-10T23:23:29.177 回答