xcode 在iphone模拟器中打开sqlite数据库文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4646692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:39:05  来源:igfitidea点击:

Open sqlite database file inside iphone simulator?

iphonexcodesqlite

提问by Mauro

I'm having a hard time trying to understand a problem in my iphone app.

我很难理解我的 iphone 应用程序中的问题。

I have a set method in my sqlite database that looks like it is working fine. I do a NSLog when I am setting the value and it is correct. It's a string with the value "2010-10-10 12:13:14".

我的 sqlite 数据库中有一个 set 方法,看起来工作正常。我在设置值时执行 NSLog 并且它是正确的。它是一个值为“2010-10-10 12:13:14”的字符串。

When I use the get method on the same data, it turns out that the value is not correct. It returns 1.

当我对相同的数据使用 get 方法时,结果发现该值不正确。它返回 1。

Is there any way to open the database file that is inside the iPhone simulator so I can see what is the actual data stored in the simulator database?

有什么方法可以打开 iPhone 模拟器内的数据库文件,以便我可以看到模拟器数据库中存储的实际数据是什么?

Is there any way to sniff the sqlite calls between my simulator and the actual file? Something like Charles, or Service Capture?

有没有办法嗅探模拟器和实际文件之间的sqlite调用?像 Charles 或 Service Capture 之类的东西?

Many thanks!

非常感谢!

采纳答案by Aditya

You can refer to the following link below,You can definitely look at the database stored inside the simulator.

你可以参考下面的链接,你绝对可以看看模拟器里面存储的数据库。

How to view the data in sqlite file running in iphone application?

如何查看在 iphone 应用程序中运行的 sqlite 文件中的数据?

Cheers

干杯

回答by bicycle

Since IOS 8 they put it in a different folder:

从 IOS 8 开始,他们将其放在不同的文件夹中:

Library/Developer/CoreSimulator/Devices/(numbers and letters)/data/Containers/Data/Application/(numbers and letters)/Documents/

Library/Developer/CoreSimulator/Devices/(numbers and letters)/data/Containers/Data/Application/(numbers and letters)/Documents/

Check this answer for more info

检查此答案以获取更多信息

回答by Vineesh TP

If you want to view the database that you have created,

如果要查看自己创建的数据库,

Open finder -> press SHIFT+ Command+ G-> "~/Library/Application Support/iPhone Simulator" then go.

打开 finder -> 按SHIFT+ Command+ G-> "~/Library/Application Support/iPhone Simulator" 然后去。

Open 5.0 (as per your version of simulator)-> Application-> select the pgm folder

打开 5.0(根据您的模拟器版本)-> 应用程序-> 选择 pgm 文件夹

-> Documents

-> 文件

enter image description here

在此处输入图片说明

Then you can see the database

然后就可以看到数据库了

enter image description here

在此处输入图片说明

回答by Nadav96

Update: I made a tool to automate this

更新:我制作了一个工具来自动化这个

Both for Android and iOS, it's available here

适用于 Android 和 iOS,可在此处获得



Old question, but Apple seem to keep change the logic...

老问题,但苹果似乎一直在改变逻辑......

On macOs Sierra you can find the database location by issuing the following commands (the simulator must run during the process!)

在 macOs Sierra 上,您可以通过发出以下命令来找到数据库位置(模拟器必须在此过程中运行!)

ps aux | grep 'CoreSimulator/Devices'

The result should list the path to the simulator, for example:

结果应列出模拟器的路径,例如:

/Users/user1/Library/Developer/CoreSimulator/Devices/25C1F5DA-E528-4BC2-B684-A92D382553AC/data/var/run/launchd_bootstrap.plist

Navigate to the now found simulator folder:

导航到现在找到的模拟器文件夹:

cd /Users/user1/Library/Developer/CoreSimulator/Devices/25C1F5DA-E528-4BC2-B684-A92D382553AC/Data/Application/

This folder contains allthe simulator applications

此文件夹包含所有模拟器应用程序

From here if you know the database name, just find it, like so:

从这里如果您知道数据库名称,只需找到它,如下所示:

find ./ -type f -name 'my_db.db'

And viola! You have the database path :)

还有中提琴!你有数据库路径:)

回答by Nick Snyder

For the 6.1 simulator, the location is different.

对于 6.1 模拟器,位置不同。

Start at:

开始于:

~/Library/Application Support/iPhone Simulator/6.1/Applications/

Open the folder that represents the application on your simulator. The name will look similar this:

打开代表模拟器上的应用程序的文件夹。该名称将类似于以下内容:

0951F670-1DAC-9A39-450A-B8EEFFC0FFE1

If you have multiple folders, then you can click into each folder and look at the app icon until you find the app that you are looking for. Alternatively, uninstall all other apps from the simulator except the one you are interested in.

如果您有多个文件夹,则可以单击每个文件夹并查看应用程序图标,直到找到您要查找的应用程序。或者,从模拟器中卸载除您感兴趣的应用程序之外的所有其他应用程序。

From inside this folder, go here:

从这个文件夹里面,去这里:

Library/Application Support/<APP_NAME>/<APP_NAME>.sqlite

The total path should look like this:

总路径应如下所示:

~/Library/Application Support/iPhone Simulator/6.1/Applications/<APP_ID>/Library/Application Support/<APP_NAME>/<APP_NAME>.sqlite

回答by Gurjinder Singh

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSLog(@"path is %@",documentsDirectory);

The above code will print the path of ur database and copy it. Go to finder and choose go to folder from menu (Shift+Win+G) and paste the path here, it will give you the exact path of core data file. Keep this window open.

上面的代码会打印你的数据库的路径并复制它。转到查找程序并从菜单 ( Shift+Win+G) 中选择转到文件夹并将路径粘贴到此处,它将为您提供核心数据文件的确切路径。保持这个窗口打开。

Next step Go to Mozilla firefox click on menubar choose Tools -> SQLite Manager. It will open new window. In new window click on open file and drag that path of coredata file in current window and click on open.

下一步转到 Mozilla firefox 单击菜单栏选择工具 -> SQLite 管理器。它将打开新窗口。在新窗口中单击打开文件并将 coredata 文件的路径拖动到当前窗口中,然后单击打开。

Note - You must have Installed SQLite Manager in your Mozilla firefox.

注意 - 您必须在 Mozilla firefox 中安装 SQLite Manager。

回答by Glenn

For 2019 and 2020 answer: ??

对于 2019 年和 2020 年的答案:??

This is easy. Use a free-opensourced application called Simsim(https://github.com/dsmelov/simsim).

这很简单。使用名为Simsim( https://github.com/dsmelov/simsim)的免费开源应用程序。

Read the README and there's a direct download link there.

阅读自述文件,那里有一个直接下载链接。

enter image description here

在此处输入图片说明



Choose Finder, and from there, you can find the .sqlitedb file in the Documentsor use the search function of the Finder targeting your application folder.

选择 Finder,从那里,您可以在应用程序文件夹中找到.sqlitedb 文件Documents或使用 Finder 的搜索功能。