UILocalNotification在后台播放10分钟后不会触发 [英] UILocalNotification does not fire after 10 minutes in background

查看:145
本文介绍了UILocalNotification在后台播放10分钟后不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VoIP应用程序。哪个工作正常。呼叫在前台和后台工作。

I have a VoIP application. Which is working fine. Call is working in foreground and background.

完成以下步骤:


  1. UIBackgroundModes => voip in Info.plist

  1. UIBackgroundModes => voip in Info.plist

配置应用程序的一个套接字用于VoIP使用。

Configured one of the app’s sockets for VoIP usage.

在移至后台之前,调用setKeepAliveTimeout:handler:

Before moving to the background, setKeepAliveTimeout:handler: is called

配置音频会话以处理转换来回使用。

Configured audio session to handle transitions to and from active use.

为了确保在iPhone上获得更好的用户体验,使用核心电话框架来调整与基于小区的电话呼叫相关的行为;

To ensure a better user experience on iPhone, used the Core Telephony framework to adjust behavior in relation to cell-based phone calls;

为了确保VoIP应用程序的良好性能,使用系统配置框架来检测网络更改并允许应用程序尽可能地休眠。

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.

现在问题是当应用程序处于后台并且来电时,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 @"";
};

现在的问题是:

按下主页按钮进入后台后,如果10分钟内有任何来电,则会触发UILocalNotification。

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分钟后停止。

It happens because background task stops after 10 minutes.

如何管理它或扩展后台任务以便长时间运行或重新启动后台任务。

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.

推荐答案

听起来你有一个接收呼叫的VoIP套接字,而不是循环和轮询呼叫状态,您可以在从套接字读取数据时显示本地通知。

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控制套接字是TCP,并标有相应的 ... NetworkServiceTypeVoIP 键,您的应用将会自动从暂停中醒来10秒,此时您可以显示本地通知。

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使用配置套接字了解更多信息信息。

See Configuring Sockets for VoIP Usage for more information.

完成后,您上面共享的所有代码都可以删除。

Once that is done, all of the code that you shared above can be removed.

这篇关于UILocalNotification在后台播放10分钟后不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆