1

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Jayshree
  • 281
  • 1
  • 6
  • 28
  • i also checked for the sms.db file. In iphone 4 i am able to access the call_history.db file located at /private/var/wireless/Library/CallHistory/call_history.db , but i am not able to access sms.db which is located at /private/var/mobile/Library/SMS/sms.db . So i am thinking it might be some thing to do with the file location. but am not sure what is happening her. can somebody plz help – Jayshree Apr 01 '11 at 10:52
  • i noticed that i am unable to access /private/var/mobile/Library folder from coding. i also checked the permissions for the mobile/Library folder and it is same as wireless/Library folder. Then too its not accessible. does nybody has an idea bout this???? – Jayshree Apr 04 '11 at 10:26
  • Share some of the code you are using. Because if your Phone is jailbroken, you should be able to access the directories without error. – WrightsCS Apr 08 '11 at 05:03
  • @ WrightsCS : i have edited my question with the code. i use the simple sqlite_open statement to open the database files. It works for ios 4 with wireless folder, but it doesnt work for ios 3.1.3 where the call_history.db is located in Library folder. – Jayshree Apr 08 '11 at 06:12
  • it looks like the UNIX owner of the sms.db is "mobile" while the owner of call_history.db is "wireless". Maybe that has something to do with it? – haider Jun 17 '11 at 22:27

2 Answers2

5

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.

WrightsCS
  • 50,551
  • 22
  • 134
  • 186
  • i am working on a jailbroken device. but still am not able to access the Library folder where the files like SMS, Notes, Calendar etc are present.what could be the reason for this, Do u think my device might not be jailbroken properly??? – Jayshree Apr 08 '11 at 06:06
  • No. If you are installing your app through xcode onto your device it will install it as a sandboxed app. You need to manually sign it using LDID and copy it to the /Applications directory. – WrightsCS Apr 08 '11 at 07:08
  • can u tell me how should i go about doing this?? how should i manually sign it using LDID?? – Jayshree Apr 08 '11 at 07:11
  • i did what u suggested. i did ldid on my .app, then copied the .app file to /Applications folder. But i still dont think it worked. how can i debug the app which is inside /Applications??? – Jayshree Apr 08 '11 at 08:48
  • moreover the app crashes on the launch itself. i doesnt go any further. – Jayshree Apr 08 '11 at 09:47
  • Jayshree: Check the syslog to see why it crashed. It could be because it's either not properly pseudo signed, or because your code doesn't expect to live in /Applications. – rpetrich Apr 09 '11 at 23:50
  • Jayshree, like rpetrich says, you probably didnt sign it correctly, if you get a SINGNAL 9 in the syslog, then thats your problem. Also, the only way to debug the app while its in /Applications is by using NSLOG throughout your code or when your app crashes check the console to see whats happening. – WrightsCS Apr 10 '11 at 00:51
  • Have a look at this link, this website challenge this functionality https://iosstuff.wordpress.com/2011/08/19/accessing-iphone-call-history/ – Anurag Sharma Jan 08 '17 at 10:27
0

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];
Hanuman
  • 642
  • 5
  • 19
  • yes, but in my this case i need to access the call_history.db which resides outside our Application's directory. Your code will fetch the files which is inside the Application's directory only. call_history.db's path is given in my question itself. – Jayshree Apr 08 '11 at 07:01
  • besides i dont think this is a problem with sqlite queries, i think it has more to do with sandboxing. – Jayshree Apr 08 '11 at 07:08
  • I mean to say instead of hardcoding the paths you can get the path dynamically 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 – Hanuman Apr 08 '11 at 09:19
  • I understood what u meant, but NSSearchPathForDirectoriesInDomain returns only the document or Library folder from Application Folder. Do u have code sample to fetch /private/var/mobile/Library/CallHistory/call_history.db. using NSSearchPath ??? – Jayshree Apr 08 '11 at 09:46