Xcode tvOS - 错误:您无权将文件“fileName.txt"保存在文件夹“Documents"中 [英] Xcode tvOS - Error: You don’t have permission to save the file “fileName.txt” in the folder “Documents”

查看:44
本文介绍了Xcode tvOS - 错误:您无权将文件“fileName.txt"保存在文件夹“Documents"中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Objective-C 中有一个 Xcode tvOS 项目.我正在尝试使用以下代码将示例 fileName.txt 文件保存到 Documents 文件夹中:

I have an Xcode tvOS project in Objective-C. I'm trying to save a sample fileName.txt file into the Documents folder with this code:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self applicationDocumentsDirectory];

    NSString *path = [[self applicationDocumentsDirectory].relativePath
                           stringByAppendingPathComponent:@"fileName.txt"];
    NSString* sampleText = @"Prova";
    NSError* err;
    [sampleText writeToFile:path atomically:YES
                           encoding:NSUTF8StringEncoding error:&err];
    if(err != nil) {
        NSLog(@"Error: %@", [err localizedDescription]);
    }
}

/**
 Returns the URL to the application's Documents directory.
 */
- (NSURL *)applicationDocumentsDirectory {
    NSLog(@"%@", [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
    inDomains:NSUserDomainMask] lastObject]);
    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
         inDomains:NSUserDomainMask] lastObject];
}


@end

但是当我运行应用程序时出现此错误:错误:您无权将文件fileName.txt"保存在文件夹Documents"中.

But I get this error when I run the app: Error: You don’t have permission to save the file "fileName.txt" in the folder "Documents".

在 iOS 中它可以代替.

In iOS it works instead.

推荐答案

您无权访问 tvOS 上的文档.

You don't have access to Documents on tvOS.

这里来自 Apple(有关详细信息,请参阅 此处):

Here is from Apple (see for details here):

您的应用程序的本地存储空间有限

Local Storage for Your App Is Limited

  • tvOS 应用程序包的最大大小为 4 GB.此外,您的应用程序可以仅访问设备本地的 500 KB 持久存储(使用 NSUserDefaults 类).在这个有限的本地之外存储时,所有其他数据必须可由操作系统清除空间低.您有几个选项可以管理这些资源:
  • 您的应用可以在 iCloud 中存储和检索用户数据.你的应用可以将它需要的数据下载到它的缓存目录中.下载的数据应用程序运行时不会被删除.但是,当空间不足时并且您的应用程序没有运行,这些数据可能会被删除.不要使用整个缓存空间,因为这会导致不可预测的结果.
  • 您的应用可以使用按需资源打包只读资产.然后,在运行时,您的应用程序请求它需要的资源,以及操作系统自动下载和管理这些资源.会心在保持用户参与的同时如何以及何时加载新资产是创建成功的应用程序的关键.有关按需信息资源,请参阅按需资源指南.这意味着每个应用程序为新 Apple TV 开发的必须能够在 iCloud 中存储数据并以提供出色客户体验的方式检索它.

这篇关于Xcode tvOS - 错误:您无权将文件“fileName.txt"保存在文件夹“Documents"中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆