gpt4 book ai didi

iphone - 在应用程序运行时阻止 Iphone iOS 中的调用和短信

转载 作者:行者123 更新时间:2023-11-28 19:12:11 26 4
gpt4 key购买 nike

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

最佳答案

下面是我从该网站改编的一些代码,适用于我的非越狱设备:

首先将“CoreTelephony.framework”添加到您的项目中,然后像这样将其导入到您的 View Controller 中:

#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();

目前这段代码只是一个概念证明,必须在错误处理和诸如此类的东西的基础上进行扩展,但你应该明白了。

关于iphone - 在应用程序运行时阻止 Iphone iOS 中的调用和短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14692551/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com