I've seen the explanation that writeToFile doesn't work with non-objects, however, this snippet shows there is a serious gap in what works on the iPad device and how the simulator works.
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.
The application only has permission to write to its Documents directory:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myLocalMovieMetaData-v11"];
Then use:
[arrayOne writeToFile:path atomically:YES];
精彩评论