开发者

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

开发者 https://www.devze.com 2023-02-04 13:47 出处:网络
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

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

精彩评论

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

关注公众号