在应用程序运行时阻止Iphone iOS中的呼叫和短信 [英] Block calls and sms in Iphone iOS while application running
问题描述
使用app时我想阻止所有来电和短信。我怎样才能做到这一点?我知道示例链接 http://tech.ruimaninfo.com/?p=83 。但是代码中有错误。它应该至少在越狱的iPhone上工作。
while using app I want to block all incoming calls and sms. How can I do this? I know example link http://tech.ruimaninfo.com/?p=83. But there are errors in code.It should work at least on jailbroken iphone.
推荐答案
下面是我改编的一些代码来自该网站,并在我的非越狱设备上为我工作:
Below is some code that I've adapted from that website, and works for me on my non jailbroken device:
首先将CoreTelephony.framework添加到您的项目中,然后将其导入您的视图控制器,如下所示: / p>
Firstly add "CoreTelephony.framework" to your project then import it into your view controller like so:
#import <CoreTelephony/CoreTelephonyDefines.h>
接下来,添加以下代码:
Next, add the following code:
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或其他一些合适的方法中,添加以下内容:
And in viewDidLoad or some other appropriate method, add the following:
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();
现在这段代码只是一个概念证明,必须扩展以进行错误处理和什么,但你应该明白这一点。
For now this code is merely a proof of concept and would have to be expanded upon for error handling and whatnot, but you should get the idea.
这篇关于在应用程序运行时阻止Iphone iOS中的呼叫和短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!