0
我想阻止所有來電和短信。我怎樣才能做到這一點?我知道例子鏈接http://tech.ruimaninfo.com/?p=83。但是在代碼中存在錯誤。它應該至少在越獄iphone上工作。在使用應用程序時阻止Iphone iOS中的呼叫和短信,同時運行應用程序
我想阻止所有來電和短信。我怎樣才能做到這一點?我知道例子鏈接http://tech.ruimaninfo.com/?p=83。但是在代碼中存在錯誤。它應該至少在越獄iphone上工作。在使用應用程序時阻止Iphone iOS中的呼叫和短信,同時運行應用程序
下面是一些代碼,我已經適應從該網站,併爲我工作我的非越獄的設備上:
首先添加「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();
現在這個代碼僅僅是一個概念證明和將會對錯誤處理和諸如此類的東西進行擴展,但你應該明白我的意思。
謝謝你的回答。所以阻止呼叫和短信在viewDidLoad函數後啓動? –
這就是你開始接收回調並最終阻止這些的地方,是的。 –
此代碼塊調用但不會阻止短信。 –