簡體   English   中英

iPhone“無法打開數據庫文件”在xcode應用程序中為call_history.db

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

我試圖在越獄的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手動檢索所有文件。

您的應用程序位於沙箱中,該沙箱無法訪問自身以外的任何內容。 假設您的目標越獄設備,這是另一回事了。

Xcode將您的應用程序安裝到沙盒環境中。 您需要使用ldid -S /YourApp.app/YourApp手動對應用程序進行簽名,然后將其復制到devices /Applications目錄。

這是我見過的最好,最簡單的教程
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];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM