如何从 iPhone 上的来电中获取来电者的电话号码

发布于 2024-11-02 18:37:27 字数 82 浏览 0 评论 0原文

你好,我想构建一个应用程序,在来电时执行某些操作。但我认为手机需要在 iPhone 上越狱才能访问执行此操作的类。我想在手机不越狱的情况下做到这一点。

Hi I want to build an app that does something when an incoming call comes in. But I think that the phone needs to be jailbroken on the iphone to access the class that does that. I want to do it without the phone being jailbroken.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆沫 2024-11-09 18:37:27

不可能。

但是,您可以使用 CoreTelephony 框架。

Not possible.

However you may get the information like call state(connected/disconnected etc) using CoreTelephony framework.

ぃ双果 2024-11-09 18:37:27

如果您想在来电或去电时执行任何操作,则必须使用此代码:

CTCallCenter *callCenter; //make it ivar if you are using ARC or handler will be auto-released...
callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler=^(CTCall* call) {
    NSLog(@"Call id:%@", call.callID);
    [self callStateChange:call.callState andId:call.callID];
    if (call.callState==CTCallStateDialing) {
       NSLog(@"Call state:dialing");
    }
    if (call.callState==CTCallStateIncoming) {
       NSLog(@"Call state:incoming");
       //here you lower your speaking volume if you want
    }
    if (call.callState==CTCallStateConnected) {
       NSLog(@"Call state:connected");
    }
    if (call.callState==CTCallStateDisconnected) {
       NSLog(@"Call state:disconnected");
    }
};

但是当您的应用程序处于活动状态或从后台转到前台时,这将起作用。如果应用程序将杀死或暂停该应用程序,则该应用程序将不起作用。首先,您检测呼叫状态,然后立即显示本地通知。当单击查看详细信息时,再次显示您的应用程序。但这并没有得到苹果的批准,因为它会在后台发送电话。所以可能会有风险。

If you want to do anything when a call come or going then you have to use this code:

CTCallCenter *callCenter; //make it ivar if you are using ARC or handler will be auto-released...
callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler=^(CTCall* call) {
    NSLog(@"Call id:%@", call.callID);
    [self callStateChange:call.callState andId:call.callID];
    if (call.callState==CTCallStateDialing) {
       NSLog(@"Call state:dialing");
    }
    if (call.callState==CTCallStateIncoming) {
       NSLog(@"Call state:incoming");
       //here you lower your speaking volume if you want
    }
    if (call.callState==CTCallStateConnected) {
       NSLog(@"Call state:connected");
    }
    if (call.callState==CTCallStateDisconnected) {
       NSLog(@"Call state:disconnected");
    }
};

but that will work when u app will active or go background to foreground. If app will kill or suspended the that will not work. First you detect state of call and then show a local notification immediately. And when click on view details then show ur app again. But this is not approved by apple because it will send phone call in background. So it may be risky.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文