我在我的应用程序中阅读 iphone 消息收件箱时遇到问题,我使用了以下代码:
- (IBAction) read{
NSString *text = @"";
sqlite3 *database;
if(sqlite3_open([@"/var/root/Library/SMS/sms.db" UTF8String], &database) == SQLITE_OK) {
sqlite3_stmt *statement;
const char *sql4 = "SELECT * from message ORDER BY rowid DESC"; // TODO: different for iOS 4.* ???
const char *sql5 = "SELECT * from message ORDER BY rowid DESC";
NSString *osVersion =[[UIDevice currentDevice] systemVersion];
if([osVersion hasPrefix:@"5"]) {
// iOS 5.* -> tested
sqlite3_prepare_v2(database, sql5, -1, &statement, NULL);
} else {
// iOS != 5.* -> untested!!!
sqlite3_prepare_v2(database, sql4, -1, &statement, NULL);
}
// Use the while loop if you want more than just the most recent message
while (sqlite3_step(statement) == SQLITE_ROW) {
if (sqlite3_step(statement) == SQLITE_ROW) {
char *content = (char *)sqlite3_column_text(statement, 0);
text = [NSString stringWithCString: content encoding: NSUTF8StringEncoding];
sqlite3_finalize(statement);
}
}
sqlite3_close(database);
}
showsms.text=text;
NSLog(@"test");
}
但我无法访问“SMS.DB”,我在互联网上搜索过,但没有人有这样的问题,请任何人对我的问题有任何想法,写下我的代码或告诉我他的方式。
谢谢