ios – setResourceValue NSURLFileProtectionKey cannot work

[ad_1]

I wrote the Goal-C code under.

- (BOOL)setFileNSFileProtectionNone:(nonnull NSString *)filePath
{
    NSURL* fileURL = [NSURL URLWithString: filePath];
    if (fileURL != nil) {
        
        NSError *error = nil;
        BOOL success = [fileURL setResourceValue:NSURLFileProtectionNone
                                      forKey:NSURLFileProtectionKey
                                       error:&error];
        if (!success) {
            NSLog(@"setFileNSFileProtectionNone error: %@", error);
            return false;
        } else {
            return true;
        }
    }
    return false;
}

I known as setResourceValue to set NSURLFileProtectionKey to NSURLFileProtectionNone after check.log0 is created, and the return worth was ture.

func applicationProtectedDataWillBecomeUnavailable(_ utility: UIApplication) {
        print("applicationProtectedDataWillBecomeUnavailable")
        
        let logPath = NSHomeDirectory().stringByAppendingPathComponent(path: "Paperwork/log")
        
        if let enumerator = FileManager.default.enumerator(atPath: logPath) {
            for case let file as String in enumerator {
                let fullpath = logPath + "/" + file
                let fileUrl = NSURL(fileURLWithPath: fullpath)
                var rsrc: AnyObject?
                do {
                    strive fileUrl.getResourceValue(&rsrc, forKey: .fileProtectionKey)
                    print("BecomeUnavailable: (file):(rsrc)")
                } catch let e {
                    print(e)
                }
            }
        }
    }

However once I known as getResourceValue when the machine is locked, I received NSURLFileProtectionComplete.

BecomeUnavailable: check.log0:Optionally available(NSURLFileProtectionComplete)

Anyone can inform me why setResourceValue cannot work?
It is pressing, thanks prematurely.

[ad_2]

Leave a Reply