【问题标题】:NSFileWrapper Error Writing to URLNSFileWrapper 错误写入 URL
【发布时间】:2013-01-20 04:50:06
【问题描述】:

我有一个存档,我正在尝试将其内容复制到 Documents 目录中。它在模拟器中运行良好,但在设备上出现错误时中止。

- (BOOL)importData:(NSData *)zippedData {

// Read data into a dir Wrapper

NSData *unzippedData = [zippedData gzipInflate];

NSFileWrapper *dirWrapper = [[[NSFileWrapper alloc] initWithSerializedRepresentation:unzippedData] autorelease];

if (dirWrapper == nil) {

    NSLog(@"Error creating dir wrapper from unzipped data");

    return FALSE;

}

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSURL *dirUrl = [NSURL fileURLWithPath:documentsDirectory];  

NSError *error;

BOOL success = [dirWrapper writeToURL:dirUrl options:NSFileWrapperWritingAtomic originalContentsURL:nil error:&error];

if (!success) {

    NSLog(@"Error importing file: %@", error.localizedDescription);

    return FALSE;

}

// Success!

return TRUE;    

}

我在控制台中得到以下输出:

2013-01-19 22:40:23.865 我的应用程序 [569:907] 名为 mkdir 的基金会(“/var/mobile/Applications/1BF53E96-6261-4DEC-8700-60307D84587F/(我的应用程序正在保存的文档)”) ,它没有返回 0,并且 errno 被设置为 1。 2013-01-19 22:40:23.922 我的应用程序[569:907] 导入文件时出错:操作无法完成。 (可可错误 513。)

【问题讨论】:

    标签: ios nsfilewrapper


    【解决方案1】:

    我认为您只能写入手机上的 Documents 目录,因此在您的 (A Document Being ...) 之前将“Documents”添加到您的目录中

    【讨论】:

      猜你喜欢
      • 2014-05-03
      • 1970-01-01
      • 2014-03-29
      • 2016-11-30
      • 2010-12-16
      • 2017-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多