加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 在Caches目录中复制Realm文件

发布时间:2020-12-14 17:55:36 所属栏目:百科 来源:网络整理
导读:我的应用程序被Apple拒绝了:“在发布和内容下载时,您的应用程序在用户的iCloud上存储了13.01 MB,这不符合iOS数据存储指南.” 我知道问题是什么.我可以将我的Realm数据库保存在Caches目录而不是Documents目录中吗? 解决方法 您可以使用Realm.Configuration.
我的应用程序被Apple拒绝了:“在发布和内容下载时,您的应用程序在用户的iCloud上存储了13.01 MB,这不符合iOS数据存储指南.”

我知道问题是什么.我可以将我的Realm数据库保存在Caches目录而不是Documents目录中吗?

解决方法

您可以使用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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读