iphone “unable to open database file” for call_his

2019-01-11 21:25发布

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

any help would be greatly appreciated. Thank you.

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 iphones through the above code. I am able to retrieve all the file manually through ssh.

2条回答
一夜七次
2楼-- · 2019-01-11 21:56

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.

查看更多
叛逆
3楼-- · 2019-01-11 22:11

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];
查看更多
登录 后发表回答