开发者

objective-c writeToFile Doesn't on iPad, Does on simulator

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜