菜鸟教程小白 发表于 2022-12-12 21:51:57

iOS PjSip - 后台工作


                                            <p><p>最近我必须使用 voip 实现后台工作应用程序。为此,我使用 PJSip。
现在我已经完成了在应用程序运行时完美地注册和处理调用。</p>

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

<p>你能帮我解决这个问题吗? </p>

<p>我已检查“免费工作 - VoiP”
我已经通过 siphon2 示例应用程序在 pjsip 中保持事件状态。</p>

<p>我也有:</p>

<pre><code>- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [ 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;

    ;
    NSLog(@&#34;startingKeepAliveTimeout1&#34;);

    [application setKeepAliveTimeout:KEEP_ALIVE_INTERVAL handler: ^{
      NSLog(@&#34;startingKeepAliveTimeout2&#34;);

      ;
    }];


    __block UIBackgroundTaskIdentifier bgTask;

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


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

         NSLog(@&#34;\n\nRunning in the background!\n\n&#34;);
    });
}
</code></pre>

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

<p>应用程序必须在 iOS7 和 iOS6 中运行</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在后台运行的应用程序,是使用 IOS 中的 setKeepAliveTimeout 方法执行的。但从以后的版本开始,setKeepAliveTimeout 方法已被弃用。</p>

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

<p> <a href="https://www.raywenderlich.com/150015/callkit-tutorial-ios" rel="noreferrer noopener nofollow">https://www.raywenderlich.com/150015/callkit-tutorial-ios</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于iOS PjSip - 后台工作,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/23364782/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/23364782/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS PjSip - 后台工作