gpt4 book ai didi

ios - 我想处理 ios 中的调用状态

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:15:59 26 4
gpt4 key购买 nike

我想知道电话的状态是已拨、接通还是断开...

我尝试了自己,但我无法获取状态。

NSString *phoneNumber = [@"telprompt://" stringByAppendingString:@"9723539389"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

CTCallCenter *callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler=^(CTCall* call)
{
if(CTCallStateDialing)
{
NSLog(@"Dialing");
}
if(CTCallStateConnected)
{
NSLog(@"Connected");
}
if(CTCallStateDisconnected)
{
NSLog(@"Disconnected");
}
};

但问题是 CTCallCenter block 从未调用过......我目前在 iOS 7 中工作

最佳答案

您应该检查 CTCall 的 callState 属性以捕获它

Use a cellular call’s CTCall object to obtain an identifier for the call and to determine the call’s state.

 extern NSString const *CTCallStateDialing;
extern NSString const *CTCallStateIncoming;
extern NSString const *CTCallStateConnected;
extern NSString const *CTCallStateDisconnected;

是字符串常量。你的 for 循环没有意义。

NSString *phoneNumber = [@"telprompt://" stringByAppendingString:@"9723539389"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

self.callCenter = [[CTCallCenter alloc] init];

[callCenter setCallEventHandler:^(CTCall* call)
{
if ([call.callState isEqualToString: CTCallStateConnected])
{
NSLog(@"Connected");
}
else if ([call.callState isEqualToString: CTCallStateDialing])
{
NSLog(@"Dialing");
}
else if ([call.callState isEqualToString: CTCallStateDisconnected])
{
NSLog(@"Disconnected");

} else if ([call.callState isEqualToString: CTCallStateIncoming])
{
NSLog(@"Incoming");
}

}];

注意:

  @property(nonatomic, strong) CTCallCenter *callCenter;

应在 Appdelegate 中声明并保留它。否则它将被视为局部变量并在循环结束后立即释放

更新:

回答“callCenter 是在 appdelegate 中声明的,我如何将它与自己一起使用?当 [] 添加到该 block 时,它会显示错误等于“预期的']'“”

用这些行替换 self.callCenter

   YourApplicationDelegateClass *appDel =(YourApplicationDelegateClass*)[UIApplication sharedApplication].delegate;

appDel.callCenter = [[CTCallCenter alloc] init];

关于ios - 我想处理 ios 中的调用状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24323282/

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