短信拦截代码
摘自:http://www.cocoachina.com/ask/questions/show/55595
参考:http://www.iteye.com/problems/84131
http://sue602.blog.163.com/blog/static/314953072009112404349325/
http://www.cnblogs.com/OtionSky/archive/2011/11/10/iPhone_TelephoneCenter.html
.首先是回调函数
static void callBack(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
if ([(NSString *)name isEqualToString:kCTMessageReceivedNotification]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@\\\"提示\\\" message:@\\\"您有新的消息哦,请注意查收!\\\" delegate:nil cancelButtonTitle:@\\\"确定\\\" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
2.通知的注册
CTTelephonyCenterAddObserver(CTTelephonyCenterGetDefault(), NULL, callBack, NULL, NULL, CFNotificationSuspensionBehaviorDrop);
3.运行代码,发送短信试试