无法使用iCloud同步简单文本文件(错误的文件描述符) [英] Cannot sync simple text file with iCloud (bad file descriptor)

查看:242
本文介绍了无法使用iCloud同步简单文本文件(错误的文件描述符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同步一个简单的文本文件时遇到问题,尝试打开时遇到此错误:

I'm having trouble synching a simple textfile, I get this error when trying to open it:

{NSFilePath = / private / var / mobile /移动文档/ 4C224W52W5〜com〜piso13〜opusDomini / currentLogPath,NSUnderlyingError = 0xde9b460操作无法完成。错误的文件描述符}

{NSFilePath=/private/var/mobile/Library/Mobile Documents/4C224W52W5~com~piso13~opusDomini/currentLogPath, NSUnderlyingError=0xde9b460 "The operation couldn’t be completed. Bad file descriptor"}

-(BOOL)createLogFolderFile{        

    NSString *uuid = nil;

    CFUUIDRef uuidRef = CFUUIDCreate(nil);

    uuid = (NSString*)CFUUIDCreateString(nil, uuidRef);

    CFRelease(uuidRef);    



    NSError *error = nil;

    [uuid writeToFile:[self filePath] atomically:NO encoding:NSUTF8StringEncoding error:&error];

    if (error) {

        NSLog(@"Error trying to create log file %@", error);        

        return FALSE;

    }

    else{

        return TRUE;

    }

}

-(NSString*)filePath{

    NSFileManager *fileManager = [NSFileManager defaultManager];

    NSString *iCloudPath = [[fileManager URLForUbiquityContainerIdentifier:nil] path];

    return [iCloudPath stringByAppendingPathComponent:LOG_FOLDER_FILE_NAME];

}

这是我读的方式:

-(NSString*)readLogFolderFromFile{

    NSError *error = nil;

    NSString *logFolder = [NSString stringWithContentsOfFile:[self filePath] encoding:NSUTF8StringEncoding error:&error];

    if (error) {

        NSLog(@"Error when trying to read log folder from file: %@" ,error);

        return nil;

    }

    else{

        return logFolder;

    }

}

使用NSMetadataQuery搜索文件
通知查询完成收集信息结果为正。

I'm using NSMetadataQuery to search for the file, The notification query finish gathering info results positive.

帮助?

推荐答案

文件没有下载。看来NSMetadataQuery通知云中文件的存在。要实际获取文件,需要额外的代码:

The file was not downloaded. It seems NSMetadataQuery notifies about the existence of the file in the cloud. To actually get the file, extra code is needed:

里面的queryDidFinish收集通知:

Inside queryDidFinishGathering notification:

 NSMetadataItem *item = [query resultAtIndex:0];
        self.metadataItem = item;
        BOOL isDownloaded = [[item valueForAttribute:NSMetadataUbiquitousItemIsDownloadedKey]boolValue];

  if (!isDownloaded) {
        NSError *error = nil;
        [[NSFileManager defaultManager] startDownloadingUbiquitousItemAtURL: [item valueForAttribute:NSMetadataItemURLKey] error:&error];
        NSLog(@"Start downloading file");
        if (error) {
            NSLog(@"Error trying to download file: %@", error);
        }
        else{
            [self lookForLogFolderFile];
            return;
        }

    }

lookForLogFolderFile只是重新开始查询。
多次调用后,我的项目被下载。您还可以在每次调用之间使用计时器来启动NSMetadataQuery。在我的情况下,只是一行文本文件。

The lookForLogFolderFile simply starts the query again. After several calls my item gets downloaded. You can also use a timer to between each call to start a NSMetadataQuery. In my case, is just a text file with one line.

这篇关于无法使用iCloud同步简单文本文件(错误的文件描述符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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