亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在IOS5上收到“ kCTMessageReceivedNotification”通知時如何獲取消息

在IOS5上收到“ kCTMessageReceivedNotification”通知時如何獲取消息

MYYA 2019-11-19 15:32:37
使用ios4.x,我可以使用以下代碼在收到“ kCTMessageReceivedNotification”通知時獲取消息CTTelephonyCenterAddObserver( ct, NULL, callback,NULL,NULL, CFNotificationSuspensionBehaviorHold); if ([notifyname isEqualToString:@"kCTMessageReceivedNotification"])//receive message    {        NSDictionary *info = (NSDictionary *)userInfo;        CFNumberRef msgID = (CFNumberRef)[info objectForKey:@"kCTMessageIdKey"];        int result;        CFNumberGetValue((CFNumberRef)msgID, kCFNumberSInt32Type, &result);           Class CTMessageCenter = NSClassFromString(@"CTMessageCenter");        id mc = [CTMessageCenter sharedMessageCenter];        id incMsg = [mc incomingMessageWithId: result];}但是使用ios5卻無法完成,因為incMsg為nil,那么我該怎么做才能得到消息?
查看完整描述

3 回答

?
回首憶惘然

TA貢獻1847條經驗 獲得超11個贊

這是我發現的...


僅查看轉儲的私有API,看起來ChatKit.framework可能會有所幫助??纯?CKSMSService.h


或CKMadridService.h用于iMessage消息。


我確實嘗試嘗試使用自己的方法,其中包括以下幾種方法CKSMSService:


- (void)_receivedMessage: (id)arg1 replace:(BOOL)arg2 replacedRecordIdentifier:(int)arg3 postInternalNotification:(BOOL)arg4;


- (void)_receivedMessage: (id)arg1 replace:(BOOL)arg2 postInternalNotification:(BOOL)arg3;

但是在iOS 5.0.1上,我沒有看到任何一個被調用(也許是我的錯誤?)。因此,我試圖直接從sqlite SMS數據庫獲取消息。注意...我沒有構建完整的應用程序來注冊通知。我假設您的代碼可以kCTMessageReceivedNotification正常使用...只是不再為您提供SMS 內容。因此,如果將以下代碼放在通知處理程序中,則應該能夠看到消息文本:


- (NSString *) mostRecentSMS  { 

    NSString *text = @"";


    sqlite3 *database;

    if(sqlite3_open([@"/private/var/mobile/Library/SMS/sms.db" UTF8String], &database) == SQLITE_OK) {

        sqlite3_stmt *statement;


        // iOS 4 and 5 may require different SQL, as the .db format may change

        const char *sql4 = "SELECT text from message ORDER BY rowid DESC";  // TODO: different for iOS 4.* ???

        const char *sql5 = "SELECT text 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);

    }

    return text;

}    

現在,請確保將此應用程序安裝在/ Applications /中。如果您僅構建此應用程序,并使用Xcode正常安裝,則由于應用程序沙箱操作,打開sqlite數據庫時會出現拒絕權限錯誤。


我的代碼段僅獲取最新的文本內容。 這是使用數據庫做更多事情的示例。看一下QuerySMS方法。


另外,這是sms.db 的數據庫格式的鏈接。您可以在那里找到其他所需的東西?;蛘撸恍鑼ms.db復制到您的計算機,然后使用Firefox SQLiteManager插件之類的文件進行瀏覽。祝好運!



查看完整回答
反對 回復 2019-11-19
?
嚕嚕噠

TA貢獻1784條經驗 獲得超7個贊

我設法在沒有越獄的iOS8設備上獲得最后一條消息:


CKDBMessage.h從ChatKit標題獲取并將文件添加到您的項目。

kCTMessageReceivedNotification通過注冊CTTelephonyCenterAddObserver

使用此功能可獲取最后收到的消息的信息:


void SmsReceived()

{

    NSLog(@"GOT SMS");


    //open IMDPersistence framework

    void *libHandle =     dlopen("/System/Library/PrivateFrameworks/IMDPersistence.framework/IMDPersistence", RTLD_NOW);


    //make/get symbol from framework + name

    IMDMessageRecordGetMessagesSequenceNumber = (int (*)())dlsym(libHandle, "IMDMessageRecordGetMessagesSequenceNumber");


    // get id of last SMS from symbol

    int lastID = IMDMessageRecordGetMessagesSequenceNumber();

    NSLog(@"%d", lastID);


    // close (release?) framework -> needed??

    dlclose(libHandle);



    // get message object

    dlopen("/System/Library/PrivateFrameworks/ChatKit.framework/ChatKit", RTLD_LAZY);

    Class CKDBMessageClass = NSClassFromString(@"CKDBMessage");// objc_getClass("CKDBMessage");

    CKDBMessage *msg = [[CKDBMessageClass alloc] initWithRecordID:lastID];


    NSString *text = msg.text;

    NSLog(@"text: %@", text);

}


查看完整回答
反對 回復 2019-11-19
  • 3 回答
  • 0 關注
  • 696 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號