Objective-c writeToFile 不适用于 iPad,适用于模拟器

发布于 2024-10-11 11:33:33 字数 546 浏览 7 评论 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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇女薄笑 2024-10-18 11:33:33

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

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

然后使用:

[arrayOne writeToFile:path atomically:YES];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文