iPhone iOS 4:如何在 Objective-C 中从后台转到前台

发布于 2024-09-12 08:00:29 字数 553 浏览 2 评论 0原文

我试图在呼叫断开后使后台的应用程序转到前台。这是代码:

if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:0123456789"]]){
  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:0123456789"]];
} else {
  // Could not make call
}

CTCallCenter *c=[[CTCallCenter alloc] init];
c.callEventHandler=^(CTCall* call){
  if(call.callState == CTCallStateDisconnected) {
    // code to make app return to the foreground
    // I have tried calling applicationWillEnterForeground, but it didn't work
  }
}

请帮忙

I am trying to make my application that is in the background come to the foreground after a call is disconnected. Here is the code:

if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:0123456789"]]){
  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:0123456789"]];
} else {
  // Could not make call
}

CTCallCenter *c=[[CTCallCenter alloc] init];
c.callEventHandler=^(CTCall* call){
  if(call.callState == CTCallStateDisconnected) {
    // code to make app return to the foreground
    // I have tried calling applicationWillEnterForeground, but it didn't work
  }
}

Please help

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

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

发布评论

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

评论(2

划一舟意中人 2024-09-19 08:00:29

我相当确定你不能通过简单的调用来做到这一点。也许注册一个 URL 处理程序 my app:// 并在完成块中使用 openURL 可以工作,但这看起来很老套。

I am fairly certain you can't do it with a simple call. Maybe registering a URL handler my app:// and usinng openURL in the completion block could work, but that seems quite hacky.

濫情▎り 2024-09-19 08:00:29

Apple 不会允许您“来到前台”,但您可以使用本地通知。

因此,对于您想做的事情,您需要:

  1. 启动拨号网址后,您将获得“applicationDidEnterBackground:”,因为您的应用程序被推送到后台。您需要启动后台任务,否则您将无法获得呼叫状态更改。

  2. 当您收到呼叫状态更改时,创建本地通知。如果用户想要“查看”您的应用程序,那么您的应用程序将进入前台。

上述有一个问题,如果通话时间超过 10 分钟,那么后台任务将被终止,您将不会看到通话状态更改。

Apple will not allow you to "come to the foreground" but you can use a local notification instead.

So for what you want to do you need to:

  1. After starting the dial url you will get a 'applicationDidEnterBackground:' as your app is pushed to the background. You will need to start a background task or else you will not get the call state change.

  2. When you get a call state change, create a local notification. If the user wants to "view" your application then you app will come to the foreground.

There is one problem with the above, if the phone call is longer than 10 min's then the background task will be terminated you will not get your call state change.

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