开发者

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

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/Ca开发者_运维知识库llHistory/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.


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜