Background task in objective c

假装没事ソ 提交于 2019-12-14 03:13:34

问题


I have a VOIP application in objective-c

SIP call is working fine when application is in foreground.

My problem is when my app is in background SIP call is not working after 10 minutes after going to background.

I have started a background task in applicationDidEnterBackground

bgTask = [application beginBackgroundTaskWithExpirationHandler:^{

    // Clean up any unfinished task business by marking where you

    // stopped or ending the task outright.

    [application endBackgroundTask:bgTask];

    bgTask = UIBackgroundTaskInvalid;

}];



// Start the long-running task and return immediately.

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{



    // Do the work associated with the task, preferably in chunks.



    [application endBackgroundTask:bgTask];

    bgTask = UIBackgroundTaskInvalid;

});

In plist file UIBackgroundModes is set to voip

I am in a patience for it.

Please any body help me. Please.


回答1:


By my understanding the beginBackgroundTaskWithExpirationHandler method is used for executing a Finite-Length Task in the Background. See Here. And there is no way extend that period of 10 mins which I have discovered.

Since your app classifies as a background mode required app, I dont think you will be needing beginBackgroundTaskWithExpirationHandler.

Read "Implementing a VoIP App" section in the above link.It advocates the use of setKeepAliveTimeout:handler: method.



来源:https://stackoverflow.com/questions/19155957/background-task-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!