【问题标题】:iPhone "unable to open database file" for call_history.db in xcode appiPhone“无法打开数据库文件”为 xcode 应用程序中的 call_history.db
【发布时间】:2011-07-26 18:41:32
【问题描述】:

我正在尝试访问越狱 iPhone 中的数据库 call_history.db。我可以使用 iOS 4.1 访问 iPhone 4 的 call_history.db。但问题是我无法使用 iOS 3.1.3 访问 iPhone 3gs 中的数据库。

当我尝试为 3gs 打开数据库时,出现以下数据库错误:

无法打开数据库文件

我对 iOS 4.1 和 iOS 3.1.3 使用不同的路径

  • iPhone 4 中的 iOS 4.1 - /private/var/wireless/Library/CallHistory/call_history.db

  • iPhone 3gs 中的 iOS 3.1.3 - /private/var/mobile/Library/CallHistory/call_history.db

更新

我通过以下方式获取 call_history.db

//NSString *path=@"/private/var/wireless/Library/CallHistory/call_history.db";//for ios 4.0 and above call_history.db
 NSString *path=@"/var/mobile/Library/CallHistory/call_history.db";//for ios 3.0 and above call_history.db

if(sqlite3_open([path UTF8String], &database) == SQLITE_OK)
{
   //code for fetching the calls goes here.////

    NSLog(@"call_history present");
}

else {

    NSLog(@"Failed to open database with message '%s'.", sqlite3_errmsg(database));
    sqlite3_close(database);
}

这里的输出是错误:

无法打开数据库文件

我注意到我无法通过上述代码访问两部 iPhone 中的 Library 文件夹。我可以通过 ssh 手动检索所有文件。

【问题讨论】:

  • 我还检查了 sms.db 文件。在 iphone 4 中,我能够访问位于 /private/var/wireless/Library/CallHistory/call_history.db 的 call_history.db 文件,但我无法访问位于 /private/var/mobile 的 sms.db /图书馆/短信/短信.db。所以我认为这可能与文件位置有关。但我不确定她发生了什么。有人可以帮忙吗
  • 我注意到我无法通过编码访问 /private/var/mobile/Library 文件夹。我还检查了移动/图书馆文件夹的权限,它与无线/图书馆文件夹相同。然后它也无法访问。有没有人有这个想法????
  • 分享一些你正在使用的代码。因为如果你的手机越狱了,你应该可以正常访问目录。
  • @WrightsCS:我已经用代码编辑了我的问题。我使用简单的 sqlite_open 语句打开数据库文件。它适用于带有无线文件夹的 ios 4,但不适用于 call_history.db 位于 Library 文件夹中的 ios 3.1.3。
  • 看起来 sms.db 的 UNIX 所有者是“移动的”,而 call_history.db 的所有者是“无线的”。也许这与它有关?

标签: iphone sqlite jailbreak


【解决方案1】:

您的应用位于沙盒中,无法访问自身之外的任何内容。假设您的目标是越狱设备,这是另一回事。

Xcode 会将您的应用安装到沙盒环境中。您需要使用 ldid -S /YourApp.app/YourApp 手动签署应用程序,然后将其复制到设备的 /Applications 目录中。

【讨论】:

  • 我正在使用越狱设备。但仍然无法访问存在 SMS、Notes、Calendar 等文件的 Library 文件夹。这可能是什么原因,你认为我的设备可能没有正确越狱吗???
  • 没有。如果您通过 xcode 将应用程序安装到您的设备上,它将作为沙盒应用程序安装。您需要使用 LDID 手动对​​其进行签名并将其复制到 /Applications 目录。
  • 你能告诉我我该怎么做吗?我应该如何使用 LDID 手动签名??
  • 我按照你的建议做了。我在我的 .app 上做了 ldid,然后将 .app 文件复制到 /Applications 文件夹。但我仍然认为它不起作用。如何调试 /Applications 中的应用程序???
  • 此外,应用程序在启动时崩溃。我没有更进一步。
【解决方案2】:

这是我见过的最好最简单的教程
http://dblog.com.au/iphone-development-tutorials/iphone-sdk-tutorial-reading-data-from-a-sqlite-database/

不要硬编码路径,试试下面。

databaseName = @"AnimalDatabase.sql";

// Get the path to the documents directory and append the databaseName
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];

【讨论】:

  • 是的,但在我的这种情况下,我需要访问位于我们应用程序目录之外的 call_history.db。您的代码将仅获取应用程序目录中的文件。我的问题本身给出了 call_history.db 的路径。
  • 除了我不认为这是 sqlite 查询的问题之外,我认为它与沙盒有关。
  • 我的意思是说,不是硬编码路径,您可以在 iphone 4 中动态获取路径 ios 4.1 - /private/var/wireless/Library/CallHistory/call_history.db 和 iphone 中的 ios 3.1.3 3gs - /private/var/mobile/Library/CallHistory/call_history.db
  • 我明白你的意思,但 NSSearchPathForDirectoriesInDomain 只返回应用程序文件夹中的文档或库文件夹。你有代码示例来获取/private/var/mobile/Library/CallHistory/call_history.db。使用 NSSearchPath ???
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-15
  • 2011-12-26
  • 2011-05-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多