奇怪:来自 iCloud 的受密码保护的 zip 文件一旦备份就会更改其格式,无法解压缩

STRANGE: Password protected zip file from iCloud changes it's format once backed up, not able to unzip them

我正在上传一个受密码保护的 zip 文件作为备份到 iCloud,它被上传,然后我下载、解压缩并使用同一个文件,只有当我们从同一个地方做所有这些很酷的事情时,它才能完美地工作设备。

考虑这种情况, 1. 从一台设备压缩并上传文件。 2. 从其他设备下载并解压(不能解压,因为它不识别文件是zip格式)

注意: 我已经通过启用我的 iTunes 文件共享来交叉验证文件已成功下载到其他设备。

但是我无法解压缩文件。

我自己找到了解决方案希望这会节省其他人的时间,将受密码保护的 zip 文件转换为数据并上传、下载、解压缩相同的文件

任何文件都可以上传到任何大小的 iCloud 容器(是的,你应该在 iCloud 中拥有那么多 space)让我们举个例子 SampleData.zip

// 1 This method will upload or sync SampleData.zip file in iCloud container, iCloud actually checks the metadata of your file before it uploads it into your iCloud container (so for first time it will upload the file and from next time it will only upload the changes)

-(void) iCloudSyncing:(id)sender
{
    //Doc dir
    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"SampleData.zip"];
    NSURL *u = [[NSURL alloc] initFileURLWithPath:filePath];
    NSData *data = [[NSData alloc] initWithContentsOfURL:u];

    //Get iCloud container URL
    NSURL *ubiq = [[NSFileManager defaultManager]URLForUbiquityContainerIdentifier:nil];// in place of nil you can add your container name
    //Create Document dir in iCloud container and upload/sync SampleData.zip
    NSURL *ubiquitousPackage = [[ubiq URLByAppendingPathComponent:@"Documents"]URLByAppendingPathComponent:@"SampleData.zip"];
    Mydoc = [[MyDocument alloc] initWithFileURL:ubiquitousPackage];
    Mydoc.zipDataContent = data;

    [Mydoc saveToURL:[Mydoc fileURL] forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success)
     {
         if (success)
         {
             NSLog(@"SampleData.zip: Synced with icloud");
         }
         else
             NSLog(@"SampleData.zip: Syncing FAILED with icloud");

     }];
}



  // 2 Download data from the iCloud Container

- (IBAction)GetData:(id)sender {

    //--------------------------Get data back from iCloud -----------------------------//
    id token = [[NSFileManager defaultManager] ubiquityIdentityToken];
    if (token == nil)
    {
        NSLog(@"ICloud Is not LogIn");
    }
    else
    {
        NSLog(@"ICloud Is LogIn");

        NSError *error = nil;
        NSURL *ubiq = [[NSFileManager defaultManager]URLForUbiquityContainerIdentifier:nil];// in place of nil you can add your container name
        NSURL *ubiquitousPackage = [[ubiq URLByAppendingPathComponent:@"Documents"]URLByAppendingPathComponent:@"SampleData.zip"];
        BOOL isFileDounloaded = [[NSFileManager defaultManager]startDownloadingUbiquitousItemAtURL:ubiquitousPackage error:&error];
        if (isFileDounloaded) {
            NSLog(@"%d",isFileDounloaded);
            NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
            //changing the file name as SampleData.zip is already present in doc directory which we have used for upload
            NSString* fileName = [NSString stringWithFormat:@"RecSampleData.zip"];
            NSString* fileAtPath = [documentsDirectory stringByAppendingPathComponent:fileName];
            NSData *dataFile = [NSData dataWithContentsOfURL:ubiquitousPackage];
            BOOL fileStatus = [dataFile writeToFile:fileAtPath atomically:NO];
            if (fileStatus) {
                NSLog(@"success");
            }
        }
        else{
            NSLog(@"%d",isFileDounloaded);
        }
    }
}

//3 voila its done :)