当 iPhone 中有来电和去电时,我们可以触发事件吗?

发布于 2024-11-25 23:46:19 字数 54 浏览 2 评论 0原文

当 iPhone 上的来电和去电结束时,我可以触发事件吗?事件的一个示例是调用 Web 服务。

Can I fire an event when ever there is Incoming and Outgoing call ends on iphone? Axample of an event is calling a webservice .

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

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

发布评论

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

评论(3

我早已燃尽 2024-12-02 23:46:19

是的,您可以,但不一定立即。

有一个名为 CoreTelephony 框架的框架,它有一个 CTCallCenter 类。此类的属性之一是 callEventHandler 属性。当电话呼叫状态发生变化时,此块就会被触发。例如:

CTCallCenter *callCenter = ...; // get a CallCenter somehow; most likely as a global object or something similar?

[callCenter setCallEventHandler:^(CTCall *call) {
  if ([[call callState] isEqual:CTCallStateConnected]) {
    //this call has just connected
  } else if ([[call callState] isEqual:CTCallStateDisconnected]) {
    //this call has just ended (dropped/hung up/etc)
  }
}];

确实你能用它做的就是这些。您无法访问任何电话号码。唯一有用的信息是 CTCall 上的标识符属性,以便您唯一地标识 CTCall 对象。

注意

除非您的应用位于前台,否则不会调用此事件处理程序!如果您在应用程序处于后台时拨打和接听电话,则事件处理程序将不会触发直到您的应用程序再次激活,此时(根据上面链接的文档)将调用事件处理程序当应用程序在后台时,每次调用改变状态一次。

Yes you can, but not necessarily immediately.

There is a framework, called the CoreTelephony framework, which has a CTCallCenter class. One of the properties on this class is the callEventHandler property. This is a block that gets fired when then state of a phone call changes. For example:

CTCallCenter *callCenter = ...; // get a CallCenter somehow; most likely as a global object or something similar?

[callCenter setCallEventHandler:^(CTCall *call) {
  if ([[call callState] isEqual:CTCallStateConnected]) {
    //this call has just connected
  } else if ([[call callState] isEqual:CTCallStateDisconnected]) {
    //this call has just ended (dropped/hung up/etc)
  }
}];

That's really about all you can do with this. You don't get access to any phone numbers. The only other useful tidbit of information is an identifier property on CTCall so you uniquely identify a CTCall object.

CAUTION:

This event handler is not invoked unless your app is in the foreground! If you make and receive calls while the app is backgrounded, the event handler will not fire until your app becomes active again, at which point (according to the documentation linked to above) the event handler will get invoked once for each call that has changed state while the app was in the background.

留一抹残留的笑 2024-12-02 23:46:19

不会,但当这些事件发生时,您确实会回调到应用程序。

    -(void)applicationWillResignActive:(UIApplication *)application{
        //our app is going to loose focus since thier is an incoming call
        [self pauseApp];
    }

    -(void)applicationDidBecomeActive:(UIApplication *)application{
            //the user declined the call and is returning to our app
            [self resumeApp];
    }

No but you do get callbacks into the app when those events happen.

    -(void)applicationWillResignActive:(UIApplication *)application{
        //our app is going to loose focus since thier is an incoming call
        [self pauseApp];
    }

    -(void)applicationDidBecomeActive:(UIApplication *)application{
            //the user declined the call and is returning to our app
            [self resumeApp];
    }
迷途知返 2024-12-02 23:46:19

不可以。从当前的 SDK 来看,这是不可能的。苹果不允许应用程序有这样的钩子。

No. As of the current SDK, this is not possible. Apple does not allow apps to have such hooks.

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