iPhone “unable to open database file” for call_history.db in xcode app

百般思念 提交于 2019-11-26 16:48:24

问题


I am trying to access database call_history.db in jailbroken iPhone. I am able to access call_history.db for iPhone 4 with iOS 4.1. But the problem is I am not able to access the database in iPhone 3gs with iOS 3.1.3.

When I try to open the database for 3gs I get the following database error:

unable to open database file

I use different paths for iOS 4.1 and iOS 3.1.3

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

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

Update

I fetch the call_history.db in the following way

//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);
}

Here the output is the error:

unable to open Database file

I noticed that I am not able to access the Library folder in both iPhone's through the above code. I am able to retrieve all the file manually through ssh.


回答1:


Your app is in a sandbox, which is not able to access anything outside of itself. Suppose your targeting jailbroken devices, this is another story.

Xcode will install your app into a sandboxed environment. You need to manually sign the app using ldid -S /YourApp.app/YourApp then copy it tom the devices /Applications directory.




回答2:


This was the best and easy tutorials i have seen
http://dblog.com.au/iphone-development-tutorials/iphone-sdk-tutorial-reading-data-from-a-sqlite-database/

Instead of hard coding the path, try below.

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];


来源:https://stackoverflow.com/questions/5498291/iphone-unable-to-open-database-file-for-call-history-db-in-xcode-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!