Regarding the Apple documentation there is no way to handle the phone state while the app is suspended : http://developer.apple.com/library/ios/#DOCUMENTATION/NetworkingInternet/Reference/CTCallCenter/Reference/Reference.html
关于苹果文档,当应用程序暂停时,没有办法处理手机状态:http://developer.apple.com/library/ios/# documentation /NetworkingInternet/Reference/CTCallCenter/Reference/Reference.html
"While it is suspended, your application does not receive call events"
Is this also true for the "background" state? (As the background state is not the same with the "suspended" app state regarding the states described in the Apple documentation)
“背景”状态也是如此吗?(由于后台状态与苹果文档中描述的状态的“暂停”应用状态不一样)
http://developer.apple.com/library/ios/文档/ iPhone /概念/ iPhoneOSProgrammingGuide / ManagingYourApplicationsFlow / ManagingYourApplicationsFlow.html
I'm handling the phone state using the following code :
我使用以下代码处理电话状态:
CTCallCenter *callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler=^(CTCall* call)
{
//call state
};
I have added a local notifications into the callEventHandler block in order to check if a call events will be received while my app is in background state but is seams that the block is not executed ( my app has a background support and all received events (via TCP) are handled correctly while the app is in background )
我增加了一个当地的通知到callEventHandler块为了检查调用事件将收到我的应用程序在后台状态但接缝块没有执行(我的程序有一个背景支持和所有收到的事件(通过TCP)正确处理在应用背景)
Any help is appreciated!
任何帮助都是赞赏!
Thanks
谢谢
3 个解决方案
#1
4
All tests that I've done I can't receive any using callEventHandler
when the application is in background. But, when the application is in foreground, all nicely work.
我所做的所有测试在应用程序处于后台时都不能使用callEventHandler。但是,当应用程序在前台时,一切都运行得很好。
The socket works, because iOS handles it for you app and deliver the packtes accordingly. But for that, you need to create a voip socket and add voip
to UIBackgroundModes
to your App-Info.plist.
这个套接字是有效的,因为iOS会为你的应用程序处理它,并相应的提供包。但为此,您需要创建一个voip套接字,并将voip添加到您的App-Info.plist的uibackgroundmode。
#2
1
You will not be able to monitor phone calls in the background using the callEventHandler
...
你将无法使用callEventHandler在后台监控电话…
However, according to this thread in apple dev forums, you can check the currentCalls
periodically in the background to determine if calls are in progress.
但是,根据apple dev论坛中的这个线程,您可以在后台定期检查currentcall,以确定调用是否正在进行。
Here is the code you should use (to check every seconds) :
这是你应该使用的代码(每秒钟检查一次):
- (void)viewDidLoad {
[super viewDidLoad];
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(phoneDetection) userInfo:nil repeats:YES];
}
- (void)phoneDetection {
_callCenter = [[CTCallCenter alloc] init]; // Here is the important part : instanciating a call center each time you want to check !
[_callCenter setCallEventHandler:^(CTCall *call) {
NSLog(@"Call detected");
}];
NSLog(@"%@", _callCenter.currentCalls);
}
#3
0
I know some apps run soundless audio files in the background to prevent from being closed after 10 minutes of inactivity.
我知道有些应用会在后台运行无声的音频文件,以防止在10分钟不活动后关闭。
Bluetooth, location, and audio can prevent the app from being completely killed.
蓝牙,位置和音频可以防止应用程序被完全杀死。
My app is able to detect incoming vs outgoing calls while in background because the app stays alive with location updates. We have used audio/bluetooth in the past.
我的应用程序能够在后台检测来电和外接来电,因为应用程序在位置更新时仍然活跃。我们过去使用过音频/蓝牙。
Without some method of "keepAlive" the OS will suspend your app until some external stimulus reactivates it (push notification, user launch, etc...)
如果没有某种“维持生命”的方法,操作系统将暂停你的应用程序,直到外部刺激重新激活它(推送通知、用户启动等)。
#1
4
All tests that I've done I can't receive any using callEventHandler
when the application is in background. But, when the application is in foreground, all nicely work.
我所做的所有测试在应用程序处于后台时都不能使用callEventHandler。但是,当应用程序在前台时,一切都运行得很好。
The socket works, because iOS handles it for you app and deliver the packtes accordingly. But for that, you need to create a voip socket and add voip
to UIBackgroundModes
to your App-Info.plist.
这个套接字是有效的,因为iOS会为你的应用程序处理它,并相应的提供包。但为此,您需要创建一个voip套接字,并将voip添加到您的App-Info.plist的uibackgroundmode。
#2
1
You will not be able to monitor phone calls in the background using the callEventHandler
...
你将无法使用callEventHandler在后台监控电话…
However, according to this thread in apple dev forums, you can check the currentCalls
periodically in the background to determine if calls are in progress.
但是,根据apple dev论坛中的这个线程,您可以在后台定期检查currentcall,以确定调用是否正在进行。
Here is the code you should use (to check every seconds) :
这是你应该使用的代码(每秒钟检查一次):
- (void)viewDidLoad {
[super viewDidLoad];
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(phoneDetection) userInfo:nil repeats:YES];
}
- (void)phoneDetection {
_callCenter = [[CTCallCenter alloc] init]; // Here is the important part : instanciating a call center each time you want to check !
[_callCenter setCallEventHandler:^(CTCall *call) {
NSLog(@"Call detected");
}];
NSLog(@"%@", _callCenter.currentCalls);
}
#3
0
I know some apps run soundless audio files in the background to prevent from being closed after 10 minutes of inactivity.
我知道有些应用会在后台运行无声的音频文件,以防止在10分钟不活动后关闭。
Bluetooth, location, and audio can prevent the app from being completely killed.
蓝牙,位置和音频可以防止应用程序被完全杀死。
My app is able to detect incoming vs outgoing calls while in background because the app stays alive with location updates. We have used audio/bluetooth in the past.
我的应用程序能够在后台检测来电和外接来电,因为应用程序在位置更新时仍然活跃。我们过去使用过音频/蓝牙。
Without some method of "keepAlive" the OS will suspend your app until some external stimulus reactivates it (push notification, user launch, etc...)
如果没有某种“维持生命”的方法,操作系统将暂停你的应用程序,直到外部刺激重新激活它(推送通知、用户启动等)。