gpt4 book ai didi

ios - 如何以编程方式检测来电

转载 作者:技术小花猫 更新时间:2023-10-29 10:31:21 24 4
gpt4 key购买 nike

我需要我的应用在有来电时发送通知(来电、接通、通话结束) 我用通知注册了我的 viewController。

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callReceived:) name:CTCallStateIncoming object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callEnded:) name:CTCallStateDisconnected object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callConnected:) name:CTCallStateConnected object:nil];

我还做了一个检查调用状态的方法

-(IBAction)checkForCall:(id)sender{
NSLog(@"call state %@ id %@",call.callState,call.callID);
CTCallCenter *callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler = ^(CTCall* call){
if (call.callState == CTCallStateDisconnected)
{
NSLog(@"Call has been disconnected");

}
else if (call.callState == CTCallStateConnected)
{
NSLog(@"Call has just been connected");

}
else if(call.callState == CTCallStateIncoming)
{
NSLog(@"Call is incoming");

}
else
{
NSLog(@"None of the conditions");
}
};
}

但是这些都不起作用。请帮助我。

错在哪里?是否有任何代码告诉如何使用核心电话?

最佳答案

使用这个

Appdelegate.h

#import <CoreTelephony/CTCallCenter.h>
#import <CoreTelephony/CTCall.h>
...
@property (nonatomic, strong) CTCallCenter* callCenter;

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
....
self.callCenter = [[CTCallCenter alloc] init];
[self handleCall];
....
}

-(void)handleCall
{
self.callCenter.callEventHandler = ^(CTCall *call){

if ([call.callState isEqualToString: CTCallStateConnected])
{
//NSLog(@"call stopped");
}
else if ([call.callState isEqualToString: CTCallStateDialing])
{
}
else if ([call.callState isEqualToString: CTCallStateDisconnected])
{
//NSLog(@"call played");
}
else if ([call.callState isEqualToString: CTCallStateIncoming])
{
//NSLog(@"call stopped");
}
};
}

关于ios - 如何以编程方式检测来电,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23535355/

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