5.1 File Locking/Unlocking

5.1.1 Lock File

The lockFile method of BayunCore class locks a file with default encryption-policy dictated by server settings.

Method parameters :
  • filePath : Path of the file to be locked.
    • dataType : NSURL
  • success : Success block to be executed after file is successfully locked.
  • failure : Failure block to be executed if file locking fails, returns BayunError.

The file at the given file path is overwritten with the locked file. If file locking fails original file is not changed.

Objective-C
Swift 3.0

NSURL *fileURL = [NSURL fileURLWithPath:@"your file path"];

[[BayunCore sharedInstance] lockFile:fileURL success:^{
    NSLog(@"File locked successfully.");
} failure:^(BayunError errorCode) {
    NSLog(@"Error locking file.");
}];

let fileURL : NSURL = NSURL(fileURLWithPath:"file path")
           
BayunCore.sharedInstance().lockFile(fileURL, success: {
   NSLog("File locked successfully.")             
}, failure: { (bayunErrorCode) in
   NSLog("Error locking file.")
})

5.1.2 Lock File with encryption-policy

The lockFile method with encryption-policy as an optional parameter locks file with the encryption key dictated by the policy. The method takes the following parameters :

  • fileURL : Path of the file to be locked.
  • encryptionPolicy : BayunEncryptionPolicy determines the key for locking.
  • keyGenerationPolicy : BayunKeyGenerationPolicy determines the policy to generate the data encryption key.
  • groupId : GroupId is required if encryptionPolicy is BayunEncryptionPolicyGroup.
  • success : Success block to be executed after file is successfully locked.
  • failure : Failure block to be executed if locking fails, returns BayunError.
Note : If encryption-policy is other than BayunEncryptionPolicyGroup then groupId should be nil.

Objective-C
Swift 3.0

NSURL *fileURL = [NSURL fileURLWithPath:@"your file path"];

[[BayunCore sharedInstance] lockFile:fileURL
                    encryptionPolicy:encryptionPolicy
                    keyGenerationPolicy:keyGenerationPolicy
                             groupId:groupId
                             success:^{
      NSLog(@"File locked successfully.");                   
} failure:^(BayunError errorCode) {
      NSLog(@"Error locking file.");
}];



let fileURL = URL(fileURLWithPath: "file path")           

BayunCore.sharedInstance().lockFile(fileURL, encryptionPolicy: .company, groupId: "", success: {
  NSLog("File unlocked successfully.")  
}, failure: { (bayunErrorCode) in
   NSLog("Error unlocking file.")             
})

5.1.3 Unlock File

The unlockFile method of BayunCore class unlocks a locked file. The method takes the following parameters :

  • filePath : Path of the file to be unlocked.
    • dataType : NSURL
  • success : Success block to be executed after file is successfully unlocked.
  • failure : Failure block to be executed if file unlocking fails, returns BayunError.

The file at the given file path is overwritten with the unlocked file.

Objective-C
Swift 3.0

NSURL *fileURL = [NSURL fileURLWithPath:@"your file path"];

[[BayunCore sharedInstance] unlockFile:fileURL success:^{
    NSLog(@"File unlocked successfully.");
} failure:^(BayunError errorCode) {
    NSLog(@"Error unlocking file.");
}];

let fileURL : NSURL = NSURL(fileURLWithPath:"file path")

BayunCore.sharedInstance().unlockFile(fileURL, success: {
   NSLog("File unlocked successfully.")
}, failure: { (bayunErrorCode) in
   NSLog("Error unlocking file.")
})

results matching ""

    No results matching ""