【问题标题】:iOS PjSip - background workingiOS PjSip - 后台工作
【发布时间】:2014-04-29 12:32:45
【问题描述】:

最近我必须使用 voip 实现后台工作应用程序。为此,我使用 PJSip。 现在,当应用程序运行时,我已经完成了注册和处理呼叫。

当应用程序进入后台时,前 10 分钟工作正常 -> 新来电被捕获并作为本地通知发送 - 所以这很好。 10 分钟后,sip 停止工作并且来电也没有到达。

你能帮我解决这个问题吗?

我已检查“免费工作 - VoiP” 我已经通过 siphon2 示例应用程序在 pjsip 中保持活动状态。

我也有:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [[PjSipService service] setIsInBackground:YES];
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    int KEEP_ALIVE_INTERVAL = 600;

    [self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES];
    NSLog(@"startingKeepAliveTimeout1");

    [application setKeepAliveTimeout:KEEP_ALIVE_INTERVAL handler: ^{
        NSLog(@"startingKeepAliveTimeout2");

        [self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES];
    }];


    __block UIBackgroundTaskIdentifier bgTask;

    bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
        [application endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    }];


    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //[self deregis];
        [application endBackgroundTask: bgTask]; //End the task so the system knows that you are done with what you need to perform
        bgTask = UIBackgroundTaskInvalid; //Invalidate the background_task

         NSLog(@"\n\nRunning in the background!\n\n");
    });
}

“keepAlive”函数为空。 我已经读过这个功能keepAlive就足够了 - 但是没有后台任务它甚至不能工作10分钟。

应用程序必须在 iOS7 和 iOS6 中运行

【问题讨论】:

    标签: ios backgroundworker pjsip


    【解决方案1】:

    在后台运行的应用程序,是使用 IOS 中的 setKeepAliveTimeout 方法执行的。但从以后的版本开始,setKeepAliveTimeout 方法已被弃用。

    您想使用远程通知来接听来电。特别是对于VOIP来电,苹果引入了Callkit框架。请按照该框架在您的 VOIP 应用程序处于后台状态时接听来电。

    https://www.raywenderlich.com/150015/callkit-tutorial-ios

    【讨论】:

      【解决方案2】:

      我正在从事具有相同要求的同一个项目,最近我遇到了同样的问题。我尝试了许多不同的解决方案,最后我发现了一些现在可以工作的东西。

      请注意,我最近找到了这个解决方案,我正在努力解决这个问题。至少目前我还没有考虑这段代码的反应。

      示例代码:

      - (void)applicationDidEnterBackground:(UIApplication *)application
      {
          [self sipConnect];
          backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
              [self endBackgroundTask];
          }];
      }
      
      -(void) endBackgroundTask
      {
          [[UIApplication sharedApplication] endBackgroundTask:backgroundTask];
          backgroundTask = UIBackgroundTaskInvalid;
      }
      

      【讨论】:

      • 我已经实现了完全相同的代码 - 它正在工作,但仅在前 10 分钟内工作
      • @daro2189:我已经实现了这段代码,它对我来说运行良好(即使在 10 分钟之后)。
      • 请告诉我你在函数“sipConnect”中做了什么
      • @daro2189: sipConnect 是一个设置与 sip 服务器连接的函数。它已经集成在我们的 Siphon 应用程序的源代码中(在 SiphonApplication.m 文件中)。
      • 你使用 TCP 还是 UPD 传输?
      【解决方案3】:

      您可能使用 UPD。为确保您使用 TCP,在设置注册商时,您需要指定类似 sip:ip_address:port;transport=tcp

      【讨论】:

        【解决方案4】:

        Apple 已弃用 keepAliveTimeoutHandler。要在applicationDidEnterBackground 时接听电话,您必须使用PushKit 框架。阅读文档以获取更多信息here

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-08-29
          • 1970-01-01
          • 2016-09-30
          相关资源
          最近更新 更多