在我的应用中阅读iphone消息收件箱

时间:2012-06-24 13:04:57

标签: iphone objective-c

在我的应用中阅读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",我已在互联网上搜索但没有人有这样的问题,因为任何人都对我的问题有任何想法写我的代码或告诉我他的办法。

谢谢

1 个答案:

答案 0 :(得分:4)

应用沙箱不允许您访问该文件。即使你确实让它发挥作用,Apple也不会允许它在商店中使用。