问题
I have seen several ways to "make sure that my app is shown again after a phone call which my app has initiated has ended" however that isn't what I want -> what I am looking for is a way to, say my app is currently running in the background doing network communications and someone calls me, I would like my app to either be able to "detect when the phone call has ended and resume my network communications" and/or "launch/resume my app back into the foreground when the phone call has ended". Is there any way to accomplish something like this and how?
回答1:
This is unsupported within iOS.
From the docs: http://developer.apple.com/iphone/library/documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html
http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Reference/CTCallCenter/Reference/Reference.html#//apple_ref/doc/uid/TP40009604
If your application is active when a call event takes place, the system dispatches the event to your handler immediately. However, call events can also take place while your application is suspended. While it is suspended, your application does not receive call events. When your application resumes the active state, it receives a single call event for each call that changed state—no matter how many state changes the call experienced while your application was suspended. The single call event sent to your handler, upon your application returning to the active state, describes the call’s state at that time.
The best you can do is detect phone calls while your app is open.
回答2:
applicationWillResignActive
is called when the app is about move from active to inactive state. So if you get a call, this method is called before your app is backgrounded.
- Use this method to pause any ongoing tasks and save any settings you need.
applicationDidBecomeActive
is called when you app becomes active again.
- Use this method to resume any tasks that were suspended. Example would be resuming your network communications
来源:https://stackoverflow.com/questions/16492337/how-to-resume-or-launch-my-app-after-a-phone-call-ends-in-ios-my-app-did-not