我目前正在尝试编写一个应用程序来拦截文本消息并根据该消息的内容使用react。
我试图挂接到 CKSMSService 类中的 _receivedMessage:(struct __CKSMSRecord *)message replace:(BOOL)replace
方法,但这似乎根本没有被调用。
有人可以告诉我我必须挂接什么函数/类吗?我需要在文本消息显示并存储到数据库之前拦截它。我在 IOS 5.0.1 上。
非常感谢任何帮助。
最佳答案
此代码段应拦截 SMS 消息 - 您可以将其扩展为其他类型的通知。也适用于 iOS 5.0.1。虽然不适用于 iMessages。与 CoreTelephony 框架链接(那里有一堆私有(private) header ,您可以对其进行类转储)
#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);
}
关于IOS越狱如何拦截短信/短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8680764/