我的应用被Apple拒绝了:“在发布和内容下载时,您的应用在用户的iCloud上存储了13.01 MB,这不符合iOS数据存储指南。”
我知道问题是什么。我可以将我的Realm数据库保存在Caches目录而不是Documents目录中吗?
答案 0 :(得分:6)
您可以使用Realm.Configuration.fileURL
更改Realm文件路径。如下所示:
let cachesDirectoryPath = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true)[0]
let cachesDirectoryURL = NSURL(fileURLWithPath: cachesDirectoryPath)
let fileURL = cachesDirectoryURL.URLByAppendingPathComponent("Default.realm")
let config = Realm.Configuration(fileURL: fileURL)
let realm = try! Realm(configuration: config)
如果您不想在每个实例化Realm中指定fileURL
,则可以使用Realm.Configuration.defaultConfiguration
。如果将配置对象设置为defaultConfiguration
,Realm()
将使用配置作为默认配置。
Realm.Configuration.defaultConfiguration = config
let realm = Realm()
另见...... https://realm.io/docs/swift/latest/#realm-configuration