I have a VoIP application. Which is working fine. Call is working in foreground and background.
我有一个VoIP应用程序。哪个工作正常。呼叫正在前台和后台工作。
Following steps are done:
完成以下步骤:
-
UIBackgroundModes => voip in Info.plist
UIBackgroundModes => voip in Info.plist
-
Configured one of the app’s sockets for VoIP usage.
为VoIP使用配置了应用程序的一个套接字。
-
Before moving to the background, setKeepAliveTimeout:handler: is called
在移动到后台之前,调用setKeepAliveTimeout:handler :.
-
Configured audio session to handle transitions to and from active use.
配置音频会话以处理与活动使用之间的转换。
-
To ensure a better user experience on iPhone, used the Core Telephony framework to adjust behavior in relation to cell-based phone calls;
为了确保在iPhone上获得更好的用户体验,使用核心电话框架来调整与基于小区的电话呼叫相关的行为;
-
To ensure good performance for VoIP app, used the System Configuration framework to detect network changes and allow app to sleep as much as possible.
为了确保VoIP应用程序的良好性能,使用系统配置框架来检测网络更改并允许应用程序尽可能地休眠。
Now the thing is when application is in background and a call comes then UILocalNotification fires for the following. And user can see a notification with two buttons CANCEL and RECEIVE
现在问题是当应用程序处于后台并且调用到来时,UILocalNotification会触发以下内容。用户可以通过两个按钮CANCEL和RECEIVE查看通知
- (void)applicationDidEnterBackground:(UIApplication *)application
{
bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
[application endBackgroundTask: bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
dispatch_async(dispatch_get_main_queue(), ^{
while ([application backgroundTimeRemaining] > 1.0) {
NSString *friend = [self checkForIncomingChat];
if ([friend length]>0) {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif) {
localNotif.alertBody = [NSString stringWithFormat: NSLocalizedString(@"%@", nil), friend];
localNotif.alertAction = NSLocalizedString(@"Receive", nil);
localNotif.soundName = @"alarmsound.caf";
localNotif.applicationIconBadgeNumber = 1;
[application presentLocalNotificationNow:localNotif];
friend = nil;
}
}
sleep(1);
}
[application endBackgroundTask:self->bgTask];
self->bgTask = UIBackgroundTaskInvalid;
});
}
- (NSString *) checkForIncomingChat {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *incall = [prefs objectForKey:@"incall"];
if ([incall length]>0) {
[prefs setObject:@"" forKey:@"incall"];
return incall;
}
return @"";
};
Now the problem is:
现在的问题是:
After going to the background by pressing home button application fires UILocalNotification if any call comes within 10 minutes.
通过按下主页按钮进入后台后,如果在10分钟内有任何来电,则会触发UILocalNotification。
After 10 minutes if any call comes it is running in the background. UILocalNotification does not fire, so user can not know anything.
10分钟后,如果有任何电话,它将在后台运行。 UILocalNotification不会触发,因此用户无法知道任何事情。
It happens because background task stops after 10 minutes.
这是因为后台任务在10分钟后停止。
How can I manage it or extend background task for long running or restart background task.
如何管理它或扩展后台任务以便长时间运行或重新启动后台任务。
More and more answer I have found after searching but nothing works for long running background task.
我在搜索后发现了越来越多的答案,但对于长时间运行的后台任务没有任何作用。
Please anybody help me. I am trying it since 2 weeks.
请有人帮助我。我试了两个星期。
1 个解决方案
#1
0
It sounds like you have a VoIP socket that you are receiving the call on, so rather than looping and polling for call state, you can just present the local notification at the point that you read the data off the socket.
听起来你有一个接收呼叫的VoIP套接字,所以你可以在从套接字读取数据时提供本地通知,而不是循环和轮询呼叫状态。
If the VoIP control socket is TCP, and marked with the appropriate ...NetworkServiceTypeVoIP
key, your app will automatically get woken up from suspension for 10 seconds, at which point you can present the local notification.
如果VoIP控制套接字是TCP,并标有相应的... NetworkServiceTypeVoIP键,您的应用程序将自动从暂停状态唤醒10秒钟,此时您可以显示本地通知。
See Configuring Sockets for VoIP Usage for more information.
有关更多信息,请参阅为VoIP使用配置套接字。
Once that is done, all of the code that you shared above can be removed.
完成后,您可以删除上面共享的所有代码。
#1
0
It sounds like you have a VoIP socket that you are receiving the call on, so rather than looping and polling for call state, you can just present the local notification at the point that you read the data off the socket.
听起来你有一个接收呼叫的VoIP套接字,所以你可以在从套接字读取数据时提供本地通知,而不是循环和轮询呼叫状态。
If the VoIP control socket is TCP, and marked with the appropriate ...NetworkServiceTypeVoIP
key, your app will automatically get woken up from suspension for 10 seconds, at which point you can present the local notification.
如果VoIP控制套接字是TCP,并标有相应的... NetworkServiceTypeVoIP键,您的应用程序将自动从暂停状态唤醒10秒钟,此时您可以显示本地通知。
See Configuring Sockets for VoIP Usage for more information.
有关更多信息,请参阅为VoIP使用配置套接字。
Once that is done, all of the code that you shared above can be removed.
完成后,您可以删除上面共享的所有代码。