2016-07-16 15 views
5

Ứng dụng của tôi bị Apple từ chối vì điều này: "Khi khởi chạy và tải xuống nội dung, ứng dụng của bạn lưu trữ 13.01 MB trên iCloud của người dùng, không tuân thủ Nguyên tắc lưu trữ dữ liệu iOS".Sao chép tập tin Realm trong Caches Directory

Tôi biết vấn đề là gì. Làm sao tôi có thể lưu cơ sở dữ liệu Realm của mình trong Caches Directory thay vì thư mục Documents?

+0

http://stackoverflow.com/questions/8489342/xcode-ios-trying-to-copy-files-to-caches-folder-on-install –

+0

đây không phải là điều tôi muốn. –

Trả lời

4

Bạn có thể sử dụng Realm.Configuration.fileURL để thay đổi đường dẫn tệp của Realm. Như sau:

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) 

Nếu bạn không muốn để xác định fileURL mỗi Realm instantiating, bạn có thể sử dụng Realm.Configuration.defaultConfiguration. Nếu bạn đặt đối tượng cấu hình thành defaultConfiguration, Realm() sẽ sử dụng cấu hình làm mặc định.

Realm.Configuration.defaultConfiguration = config 
let realm = Realm() 

Xem thêm ... https://realm.io/docs/swift/latest/#realm-configuration

Các vấn đề liên quan