我尝试创建一些目录并将其从 iCloud 备份中排除:
// create directory - someDir
NSFileManager.defaultManager().createDirectoryAtURL(someDir, withIntermediateDirectories: true, attributes: nil)
// set the directory to be excluded from iCloud backup
someDir.setResourceValue(true, forKey: NSURLIsExcludedFromBackupKey)
我正在考虑将代码放在 AppDelegate.swift
的 application:didFinishLaunchingWithOptions
中,正确吗?
放置代码的正确位置(创建目录和 setResourceValue)在哪里?
最佳答案
如果您的应用程序在运行时需要此目录,那么您应该在 didFinishLaunchingWithOptions 中添加代码来创建它。检查该目录是否已存在,如果不存在,则创建它。我以前在应用程序中做过这样的事情,并且这些应用程序已经运行了一年多。
我建议创建或使用一个单独的类,您可以在其中放置所有代码详细信息,然后从 didFinishLaunchingWithOptions 中调用 if 。这使得 AppDelegate 中的代码最少。
关于ios - 创建目录和调用 setResourceValue 的正确位置在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36204653/