如何在iOS项目中正确配置Realm数据库文件(< db_name> .realm)的路径? [英] How to correctly configure path for the Realm DB-file (<db_name>.realm) in iOS project?

查看:288
本文介绍了如何在iOS项目中正确配置Realm数据库文件(< db_name> .realm)的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我的英语.

我已经开发了一个需要自己的本地数据存储的移动应用程序.我选择Realm作为数据库管理系统.在研究Realm文档的过程中,我对数据库设计没有任何问题,包括规范化,CRUD操作以及与代码直接相关的所有内容.

我很困惑.我在模拟器中测试我的应用程序.我没有创建本地数据库.我刚刚完成了Realm文档中编写的操作.领域是由它自己创建的数据库,我没有指定任何设置.我的文件与数据库的位置在下面给出:
/Users/macbookpro/Library/Developer/CoreSimulator/Devices//EFECD945-285C-494F-8C1B-950D9AA05147/data/Containers/Data/Application/8D71FF0A-60D2-4875-96BB-36955E80D505/Documents/default.realm. >

每次使用此路径来分析数据库中的记录时,我都很不方便.该文件存储在该路径下,对于Realm Browser来说是不可访问的,因为我需要root特权.我已经看到人们将他们的.realm文件存储在项目目录中.请回答我-我该怎么办?会是正确的选择吗?

我反复看过代码,其中出现了数据库文件的路径.例如,在这里:解决方案

在应用中未为默认Realm指定路径时,Realm会在应用的Documents目录中自动创建一个名为default.realm的路径.在运行iOS Simulator的应用程序上,这会将Realm文件保存在适当的Simulator文件夹中,但是您是正确的,因为找到它不是很直观.

针对您的问题:

  1. 有一个很酷的实用程序,名为 SimPholders ,可让您检查iOS模拟器中应用程序的Documents文件夹.这是获取模拟器快速生成的任何Realm文件的最佳方法.

  2. 创建Realm对象的实例时,可以提供Configuration对象以对其进行自定义.您可以通过设置Configuration对象的path属性来显式设置Realm文件的文件路径.

  3. iOS在磁盘上提供了文件自动加密层,使设备锁定时无法读取文件.如果需要更高的安全性,则可以设置Realm Configuration对象的encryptionKey属性,以使Realm自身对磁盘上的Realm文件进行加密.

希望对您有所帮助!让我知道是否需要更多说明!

Sorry for my english.

I have developed a mobile application that needs its own local data store. I chose Realm as the database management system. In the process of studying the Realm documentation I had no problems with the database design, it's normalization, the CRUD-operations and everything that is related directly to the code.

I was confused following. I test my application in the simulator. I did not create the local database. I’ve just done it as it is written in the documentation of Realm. Realm created by itself its database and I did not specify any settings. The location of my file with database is given below:
/Users/macbookpro/Library/Developer/CoreSimulator/Devices//EFECD945-285C-494F-8C1B-950D9AA05147/data/Containers/Data/Application/8D71FF0A-60D2-4875-96BB-36955E80D505/Documents/default.realm.

I quite inconvenient to apply each time this path for the analyzing of records in the database. The file is stored at this path is inaccessible for Realm Browser, because I need root privileges. I have seen that people store their .realm-files in project directory. Answer me please - how can I do it? Would it be the right alternative?

I have repeatedly seen the code, where paths to the database file appeared. For example, here: https://github.com/pietbrauer/CarthageRealmUploadFailureExample/blob/master/Carthage.checkout/realm-cocoa/examples/ios/swift/Migration/AppDelegate.swift I'm not sure if it's the right direction.

As a result, I want to:

1) have on hand a database file and be able to quickly refer to it;

2) know the algorithm - how to set own path to the Realm-database file;

3) know what realm configuration must be on a real device, to ensure security and data integrity.

Thank you very much to all!

解决方案

When you don't specify a path for the default Realm in your app, Realm will automatically create one named default.realm in the Documents directory of your app. On apps running in the iOS Simulator, this will save the Realm file in the appropriate Simulator folder, but you are correct in that it's not very intuitive to find it.

In response to your questions:

  1. There is a cool utility called SimPholders that lets you inspect the Documents folders of apps in the iOS Simulator. This is the best way to get at any Realm files the Simulator has generated very quickly.

  2. When creating an instance of a Realm object, you can supply a Configuration object to customise it. You can explicitly set the file path of the Realm file by setting the path property of that Configuration object.

  3. iOS supplies an automatic layer of file encryption on disk, that makes files unable to be read when the device is locked. If you want additional security, then it's possible to set the encryptionKey property of a Realm Configuration object to have a Realm itself encrypt that Realm file on disk.

I hope that helped! Let me know if you need any more clarification!

这篇关于如何在iOS项目中正确配置Realm数据库文件(< db_name> .realm)的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆