久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

收到“kCTMessageReceivedNotification"時如何獲取消

how to get the message when receiving the quot;kCTMessageReceivedNotificationquot; notification on IOS5(收到“kCTMessageReceivedNotification時如何獲取消息?IOS5通知)
本文介紹了收到“kCTMessageReceivedNotification"時如何獲取消息?IOS5通知的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

使用 ios4.x 我可以在收到kCTMessageReceivedNotification"通知時使用下面的代碼來獲取消息

With ios4.x I can use code below to get the message when get the "kCTMessageReceivedNotification" notification

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,所以我該怎么做才能得到消息?

But with ios5 I can't do it as incMsg is nil,so what can i do to get the message?

謝謝

推薦答案

這是我發現的...

僅查看轉儲的私有 API,ChatKit.framework 似乎可以提供幫助.看一眼CKSMSService.h

Just looking at the dumped private APIs, it looks like ChatKit.framework could help. Take a look at CKSMSService.h

或 CKMadridService.hiMessage 消息.

or CKMadridService.h for iMessage messages.

我確實很快嘗試在 CKSMSService 中混合我自己的方法:

I did quickly attempt to swizzle my own method in, for a couple methods in 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 content 了.因此,如果您將以下代碼放入通知處理程序中,您應該能夠看到消息文本:

but on iOS 5.0.1 I didn't see either of those get called (maybe my error?). So, I tried to just get the message directly from the sqlite SMS database. Note ... I didn't build the full app, to register for notifications. I'm assuming your code to get the kCTMessageReceivedNotification is ok ... it just doesn't give you the SMS content anymore. So, if you put the following code in your notification handler, you should be able to see the message text:

- (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 數據庫時收到權限被拒絕錯誤.

Now, make sure this app is installed in /Applications/. If you just build this app, and install normally with Xcode, you'll get a permission denied error opening the sqlite database, because of app sandboxing.

我的代碼片段只是獲取最新的文本內容.這是一個對數據庫進行更多操作的示例.查看 QuerySMS 方法.

My code snippet just gets the most recent text content. Here's an example of doing a little more with the database. Look at the QuerySMS method.

另外,這里是 的關于數據庫格式的鏈接短信.d??b.你可以在那里找到你需要的其他東西.或者,只需將 sms.db 復制到您的計算機,然后使用類似 Firefox SQLiteManager 插件.祝你好運!

Also, here's a link on the database format of sms.db. You can find what else you need in there. Or, just copy the sms.db to your computer, and browse it with something like the Firefox SQLiteManager plugin. Good luck!

更新:一些信息來自 我發布的關于 iOS 上多進程 SQLite 線程安全的問題

這篇關于收到“kCTMessageReceivedNotification"時如何獲取消息?IOS5通知的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Can#39;t change target membership visibility in Xcode 4.5(無法更改 Xcode 4.5 中的目標成員身份可見性)
UITableView: Handle cell selection in a mixed cell table view static and dynamic cells(UITableView:在混合單元格表視圖靜態和動態單元格中處理單元格選擇)
How to remove Address Bar in Safari in iOS?(如何在 iOS 中刪除 Safari 中的地址欄?)
iOS 5 SDK is gone after upgrade to Xcode 4.5(升級到 Xcode 4.5 后,iOS 5 SDK 消失了)
Having trouble creating UIImage from CIImage in iOS5(在 iOS5 中從 CIImage 創建 UIImage 時遇到問題)
Open target=quot;_blankquot; links outside of UIWebView in Safari(打開目標=“_blank;Safari 中 UIWebView 之外的鏈接)
主站蜘蛛池模板: 亚洲激情一区二区三区 | 毛片a | 日韩精品免费在线 | jlzzjlzz国产精品久久 | 国产欧美日韩综合精品一区二区 | av日韩高清 | 91精品国产91久久久久久最新 | 四虎永久影院 | 久久一区二区av | 国产精品一区二区在线 | 午夜免费观看网站 | 成人在线精品 | 久久99精品国产 | 欧美日韩在线视频一区二区 | 天堂男人av | 国产韩国精品一区二区三区 | 亚洲精品电影在线观看 | 成人亚洲性情网站www在线观看 | 日韩中文字幕在线视频 | 在线视频国产一区 | 国产视频福利一区 | 日韩精品一区二区三区第95 | 亚洲精品一区二区网址 | 天天干天天想 | 亚洲一区久久久 | 欧美一级片在线看 | 久久97精品| 成人三区四区 | 成人免费看片又大又黄 | 九九热精品视频 | 国产中文在线 | 瑟瑟免费视频 | 国产福利在线视频 | 九九热免费视频在线观看 | 97国产超碰| 国产视频导航 | 精品国产乱码久久久久久丨区2区 | 欧美成人精品一区 | 日韩欧美天堂 | 国产区视频在线观看 | 亚洲成人午夜在线 |