iPhone应用程序运行时阻止iPhone中的通话和短信

而使用应用程序,我想阻止所有来电和短信。 我怎样才能做到这一点? 我知道例子链接http://tech.ruimaninfo.com/?p=83 。 但是代码有错误,至less应该在越狱iphone上工作。

下面是我从该网站改编的一些代码,并在我的非越狱设备上为我工作:

首先将“CoreTelephony.framework”添加到您的项目中,然后将其导入到您的视图控制器中,如下所示:

#import <CoreTelephony/CoreTelephonyDefines.h> 

接下来,添加下面的代码:

 extern NSString const *kCTSMSMessageReceivedNotification; extern NSString const *kCTSMSMessageReplaceReceivedNotification; extern NSString const *kCTSIMSupportSIMStatusNotInserted; extern NSString const *kCTSIMSupportSIMStatusReady; typedef struct __CTCall CTCall; extern NSString *CTCallCopyAddress(void*, CTCall *); void * CTSMSMessageSend(id server,id msg); typedef struct __CTSMSMessage CTSMSMessage; NSString *CTSMSMessageCopyAddress(void *, CTSMSMessage *); NSString *CTSMSMessageCopyText(void *, CTSMSMessage *); int CTSMSMessageGetRecordIdentifier(void * msg); NSString * CTSIMSupportGetSIMStatus(); NSString * CTSIMSupportCopyMobileSubscriberIdentity(); id CTSMSMessageCreate(void* unknow/*always 0*/,NSString* number,NSString* text); void * CTSMSMessageCreateReply(void* unknow/*always 0*/,void * forwardTo,NSString *text); id CTTelephonyCenterGetDefault(void); void CTTelephonyCenterAddObserver(id, id, CFNotificationCallback, NSString *, void *,int); void CTTelephonyCenterRemoveObserver(id,id,NSString*,void*); int CTSMSMessageGetUnreadCount(void); void * CTCallDisconnect(CTCall *call); static void callback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { NSString *notifyname = (__bridge NSString *)name; if ([notifyname isEqualToString:@"kCTCallIdentificationChangeNotification"]) { NSDictionary *info = (__bridge NSDictionary *)userInfo; CTCall *call = (__bridge CTCall *)[info objectForKey:@"kCTCall"]; NSString *caller = CTCallCopyAddress(NULL, call); NSLog(@"RECEIVED CALL: %@", caller); CTCallDisconnect(call); } } static void signalHandler(int sigraised) { printf("\nInterrupted.\n"); exit(0); } 

并在viewDidLoad或其他适当的方法,添加以下内容:

 id ct = CTTelephonyCenterGetDefault(); CTTelephonyCenterAddObserver(ct, NULL, callback, NULL, NULL, CFNotificationSuspensionBehaviorHold); sig_t oldHandler = signal(SIGINT, signalHandler); if (oldHandler == SIG_ERR) { printf("Could not establish new signal handler"); exit(1); } printf("Starting run loop and watching for notification.\n"); CFRunLoopRun(); 

现在这个代码只是一个概念的certificate,而且必须扩展到error handling和什么,但是你应该明白这个想法。