【问题标题】:How to hide folder in NSDocumentsDirectory and disallow backup via iTunes & iCloud如何在 NSDocumentsDirectory 中隐藏文件夹并禁止通过 iTunes 和 iCloud 进行备份
【发布时间】:2014-05-04 19:26:41
【问题描述】:

我在 NSDocumentDirectory 中创建了私人文件夹,我想将其隐藏在 iTunes 中并禁止备份。

在这个问题How to hide folders created in Document Directory in ios?人们建议保存在私人目录中。

但是根据苹果文档https://developer.apple.com/library/mac/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html是不行的

Application_Home/Library/ 您不应将此目录用于用户数据文件。

在 iTunes11 之前,这个解决方案对我有用

Can I add the Do not Back up for the "Document Directory" for iCloud

但现在我在 iTunes 中看到带有私人文档的文​​件夹。

有人可以帮我吗?

【问题讨论】:

    标签: ios backup nsdocumentdirectory


    【解决方案1】:

    要从 iTunes 文件共享中隐藏您的应用,您可以在 info.plist 中将以下密钥设置为 No

    应用程序支持 iTunes 文件共享

    或者,在您的文件名/目录前面添加带有 . 的 Documents 目录以在不禁用 iTunes 文件共享的情况下隐藏它。例如。 .folderName.

    使用它来防止 iCloud 备份,来自Prevent Backup to iCloud,is following code correct?

    - (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *)filePathString {
        NSURL *fileURL = [NSURL fileURLWithPath:filePathString];
    
        assert([[NSFileManager defaultManager] fileExistsAtPath: [fileURL path]]);
    
        NSError *error = nil;
    
        BOOL success = [fileURL setResourceValue:[NSNumber numberWithBool: YES]
                                      forKey: NSURLIsExcludedFromBackupKey
                                     error: &error];
        return success;
    }
    

    为了防止在设备锁定时从 XCode Organizer 备份应用程序,请使用这个 sn-p

    //************************************************************************
    // Method for making files and folders secure
    //************************************************************************
    + (void)makeItemAtPathSecure:(NSString *)path
    {
        NSError *securingFilesError;
    
        NSFileManager *manager=[NSFileManager defaultManager];
    
        NSDictionary *attrs = [manager attributesOfItemAtPath:path error:&securingFilesError];
    
    
        if(![[attrs objectForKey:NSFileProtectionKey] isEqual:NSFileProtectionComplete])
        {
    
            if(![manager setAttributes:[NSDictionary dictionaryWithObject:NSFileProtectionComplete                                                                       forKey:NSFileProtectionKey] ofItemAtPath:path error:&securingFilesError])
            {
                NSLog(@"Problem in securing files: %@",[securingFilesError localizedDescription]);
            }
        }
    
        else
        {
            NSLog(@"Problem in securing files: %@",[securingFilesError localizedDescription]);
    
        }
    
    }
    

    要在 iTunes 中选择性地隐藏文件夹,请尝试使用 .在它之前,像 folderName 应该是 .folderName

    【讨论】:

      猜你喜欢
      • 2016-07-18
      • 1970-01-01
      • 1970-01-01
      • 2012-10-09
      • 1970-01-01
      • 1970-01-01
      • 2013-04-17
      • 2016-05-27
      • 2015-01-19
      相关资源
      最近更新 更多