iPhone iOS 4:如何在 Objective-C 中从后台转到前台
我试图在呼叫断开后使后台的应用程序转到前台。这是代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相当确定你不能通过简单的调用来做到这一点。也许注册一个 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.
Apple 不会允许您“来到前台”,但您可以使用本地通知。
因此,对于您想做的事情,您需要:
启动拨号网址后,您将获得“applicationDidEnterBackground:”,因为您的应用程序被推送到后台。您需要启动后台任务,否则您将无法获得呼叫状态更改。
当您收到呼叫状态更改时,创建本地通知。如果用户想要“查看”您的应用程序,那么您的应用程序将进入前台。
上述有一个问题,如果通话时间超过 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:
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.
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.