我有一个VoIP应用程序。哪个工作正常。呼叫在前台和后台工作。UILocalNotification在后台10分钟后不会触发
以下步骤进行:
UIBackgroundModes =>在Info.plist中
VOIP配置的应用程序的接口,用于网络电话使用的一个。
之前移动到背景,setKeepAliveTimeout:处理器:被称为
配置音频会话处理过渡到和积极利用。
为确保iPhone上更好的用户体验,使用核心电话框架来调整与基于蜂窝电话呼叫相关的行为;
为了确保VoIP应用程序的良好性能,使用系统配置框架来检测网络更改并允许应用程序尽可能多地休眠。
现在的事情是,当应用程序在后台,并有电话打进来,然后UILocalNotification火灾理由如下:并且用户可以看到两个按钮通知取消和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 @"";
};
现在的问题是:
按home键应用火灾UILocalNotification去后台如有电话进来后10分钟内。
10分钟后,如果有任何来电,它会在后台运行。 UILocalNotification不会触发,所以用户不知道任何事情。
发生这种情况是因为后台任务在10分钟后停止。
如何管理它或延长后台任务以便长时间运行或重新启动后台任务。
越来越多的答案我搜索后发现,但没有长期运行的后台任务的作品。
请有人帮助我。我从2周开始尝试。
我有一个类似的问题...我发现我的应用程序禁用“背景..”在设置/后台应用程序刷新..(iOS7) – TonyMkenu
你如何解决它在以前的版本?我正在使用* iPhone-3gs *,* iPhone-4 *,* iPhone-5 * – Salim