我目前正在尝试编写一个拦截文本消息的应用程序,并根据该消息的内容做出反应.我试图_receivedMessage:(struct __CKSMSRecord *)message replace:(BOOL)replace在CKSMSService类中挂钩方法,但这似乎根本没有被调用.
有人可以告诉我我必须挂钩的功能/类吗?我需要在文本消息显示并存储到数据库之前拦截它.我在IOS 5.0.1上.
真的很感激任何帮助.
使用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];}
Run Code Online (Sandbox Code Playgroud)
但是对于ios5我不能这样做因为incMsg是零,所以我该怎么做才能得到消息?
谢谢