[英]IOS Jailbreak How do intercept SMS / Text Messages
我目前正在嘗試編寫一個攔截文本消息並根據該消息內容做出反應的應用程序。 我試圖掛鈎到_receivedMessage:(struct __CKSMSRecord *)message replace:(BOOL)replace
方法,但這似乎根本沒有被調用。
有人可以告訴我我必須連接什么函數/類嗎? 我需要在文本消息顯示並存儲到數據庫之前對其進行攔截。 我在IOS 5.0.1上。
任何幫助,我們都感激不盡。
此代碼段應攔截SMS消息-您可以將其擴展為其他類型的通知。 同樣適用於iOS 5.0.1。 但是不適用於iMessages。 與CoreTelephony框架鏈接(那里有一堆私有標頭,您可以對其進行類轉儲)
#include <dlfcn.h>
#define CORETELPATH "/System/Library/PrivateFrameworks/CoreTelephony.framework/CoreTelephony"
id(*CTTelephonyCenterGetDefault)();
void (*CTTelephonyCenterAddObserver) (id,id,CFNotificationCallback,NSString*,void*,int);
static void telephonyEventCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
NSString *notifyname=(NSString *)name;
if ([notifyname isEqualToString:@"kCTMessageReceivedNotification"])//received SMS
{
NSLog(@" SMS Notification Received :kCTMessageReceivedNotification");
// Do blocking here.
}
}
-(void) registerCallback {
void *handle = dlopen(CORETELPATH, RTLD_LAZY);
CTTelephonyCenterGetDefault = dlsym(handle, "CTTelephonyCenterGetDefault");
CTTelephonyCenterAddObserver = dlsym(handle,"CTTelephonyCenterAddObserver");
dlclose(handle);
id ct = CTTelephonyCenterGetDefault();
CTTelephonyCenterAddObserver(
ct,
NULL,
telephonyEventCallback,
NULL,
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
}
盡管發布者已經接受了rajagp的回答 ,但我敢肯定,它在iOS 5上並沒有真正解決問題。 對於iOS 5,盡管我確實收到一條新消息的通知,但我再也看不到消息內容 。
因此,我所做的是將rajagp的通知處理程序用於kCTMessageReceivedNotification
,並在其中使用從此處發布的代碼從SMS數據庫中實際獲取文本消息的內容 。
在iOS 7上仍然可以使用,但是我發現收到kCTMessageReceivedNotification通知后需要稍作延遲。 否則,您將錯過剛剛收到的短信。 我使用[secureSelector .. afterDelay:0.1]的延遲時間為0.1秒;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.