找到你要的答案

Q:Disabling iCloud backup, tmp directory and replacement of files in path

Q:禁用iCloud的备份路径文件,tmp目录和更换

I currently save and read from disk on my application with these 2 methods I created:

func unarchiveWithFileName(fileName: String) -> AnyObject? {
    let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
    let documentsDirectory = paths[0] as String
    let path = "\(documentsDirectory)/\(fileName)"
    return NSKeyedUnarchiver.unarchiveObjectWithFile(path)
}

func archiveObjectWithFileName(fileName: String, object: AnyObject) {
    let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
    let documentsDirectory = paths[0] as String
    let path = "\(documentsDirectory)/\(fileName)"
    NSKeyedArchiver.archiveRootObject(object, toFile: path)
}

And my application got rejected for "storing on user's iCloud", and I have a few questions.

I came across this function for disabling iCloud backup:

- (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *) filePathString
{
    NSURL* URL= [NSURL fileURLWithPath: filePathString];
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

    NSError *error = nil;
    BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
                              forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }
    return success;
}

But what should I apply it on?

In addition, in my application I save temporary files which I replace all the time with new files. Apple told me I should save these on the tmp directory, but will my app get rejected if I save it on the documents directory?

And my last question is, as I've said in my last question, I replace files all the time. Apple mentioned I should make sure I delete the temporary files, but can I simply replace them at the path? For example:

archiveObjectWithFileName("fn", NSString())
and afterwards
archiveObjectWithFileName("fn", UIImage())

Will the file simply get replaced or I still need to remove it?

我用我创建的这2种方法在我的应用程序上保存和读取磁盘:

func unarchiveWithFileName(fileName: String) -> AnyObject? {
    let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
    let documentsDirectory = paths[0] as String
    let path = "\(documentsDirectory)/\(fileName)"
    return NSKeyedUnarchiver.unarchiveObjectWithFile(path)
}

func archiveObjectWithFileName(fileName: String, object: AnyObject) {
    let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
    let documentsDirectory = paths[0] as String
    let path = "\(documentsDirectory)/\(fileName)"
    NSKeyedArchiver.archiveRootObject(object, toFile: path)
}

我拒绝了“应用存储在用户的iCloud”,我有几个问题。

我发现这个功能禁用iCloud备份:

- (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *) filePathString
{
    NSURL* URL= [NSURL fileURLWithPath: filePathString];
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

    NSError *error = nil;
    BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
                              forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }
    return success;
}

但是我应该用什么呢?

此外,在我的应用程序,我保存临时文件,我用新的文件替换所有的时间。苹果告诉我应该保存在tmp目录,但是我的应用程序会被我保存在文件目录拒绝吗?

最后一个问题是,正如我在上一个问题中所说的,我一直在替换文件。苹果提到我应该确保我删除临时文件,但我可以简单地替换它们的路径?例如:

archiveObjectWithFileName("fn", NSString())
and afterwards
archiveObjectWithFileName("fn", UIImage())

文件将被替换或我仍然需要删除它?

ios  objective-c  swift  nsdocumentdirectory