且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS应用程序在后台任务结束后运行

更新时间:2023-02-09 18:50:07

已解决。
原因是为后台模式准备tcp连接不当。



对我来说是正确的方法:


  1. 为BSD套接字创建一对流(我使用bsd套接字)

  2. 为这两个流设置kCFStreamPropertyShouldCloseNativeSocket为kCFBooleanFalse

  3. 为这两个流设置kCFStreamNetworkServiceType为kCFStreamNetworkServiceTypeVoIP

步骤1)-3)从服务器接收到第一个数据后运行。

I made custom voip application. Almost everything works nice; but time from time application is restarted.

From crash log:
Exception Type:  00000020
Exception Codes: 0xbad22222
Highlighted Thread:  4

SBUnsuspendLimit CryptTalkDev[24820] exceeded 15 wakes in 300 sec

Highlighted thread call stack:
Thread 4 name:  com.apple.NSURLConnectionLoader
Thread 4:
0   libsystem_kernel.dylib          0x35eab004 0x35eaa000 + 4100
1   libsystem_kernel.dylib          0x35eab1fa 0x35eaa000 + 4602
2   CoreFoundation                  0x355d93ec 0x3554c000 + 578540
3   CoreFoundation                  0x355d8124 0x3554c000 + 573732
4   CoreFoundation                  0x3555b49e 0x3554c000 + 62622
5   CoreFoundation                  0x3555b366 0x3554c000 + 62310
6   Foundation                      0x35094bb2 0x35084000 + 68530
7   Foundation                      0x35094a7a 0x35084000 + 68218
8   Foundation                      0x3512858a 0x35084000 + 673162
9   libsystem_c.dylib               0x329c872e 0x329ba000 + 59182
10  libsystem_c.dylib               0x329c85e8 0x329ba000 + 58856

There is no incoming traffic in this time - i checked from application logs.

Before in several minutes application receives the network change notification and starts reregistering on server. The background task starts to protect it. In one minute before crash background task finished. But application runs anyway - i see it in logs!

What can be cause?

P.S. Checked today console:

Dec  4 13:57:36 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:57:36 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:57:46 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:57:46 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:57:56 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:57:56 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:58:06 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:58:06 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:58:16 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:58:16 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:58:27 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:58:27 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:58:37 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:58:37 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:58:47 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:58:47 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:58:57 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:58:57 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:59:07 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:59:07 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:59:17 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:59:17 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:59:27 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:59:27 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:59:37 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:59:37 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:59:47 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:59:47 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:59:57 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 13:59:58 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 14:00:08 unknown SpringBoard[51] <Warning>: Unable to deliver SBApplicationNotificationStateChanged notification to port com.apple.springboard.appstatechanged: (ipc/send) timed out
Dec  4 14:00:08 unknown SpringBoard[51] <Warning>: SBUnsuspendLimit CryptTalkDev[3925] exceeded 15 wakes in 300 sec
Dec  4 14:00:08 unknown SpringBoard[51] <Warning>: Forcing crash report of CryptTalkDev[3925]...
Dec  4 14:00:09 unknown ReportCrash[3956] <Notice>: Formulating crash report for process ReportCrash[3955]
Dec  4 14:00:09 unknown SpringBoard[51] <Error>: simulatecrash call failed with status (-308)
Dec  4 14:00:09 unknown SpringBoard[51] <Warning>: Finished crash reporting.

P.P.S. Today runs I/O activity instrument on application. Discovered two things: 1) Application resumes every 10 seconds, suspends for 100-200 ms, and resumes again 2) There are socket I/O in iOS system calls; not SIP signalling socket. Looks it is similar to http://trac.pjsip.org/repos/ticket/1482

But hard part is to find disconnected tcp socket...

Resolved. The cause was improper preparing of tcp connection for background mode.

The right way for me:

  1. Create pair of streams for BSD socket (i use bsd sockets)
  2. Set kCFStreamPropertyShouldCloseNativeSocket to kCFBooleanFalse for both streams
  3. Set kCFStreamNetworkServiceType to kCFStreamNetworkServiceTypeVoIP for both streams

Steps 1) - 3) runs after receiving of first data from server.