我正在开发一个始终在后台运行的 BLE 应用程序。它从 BLE 外围设备获取健康相关数据,并将数据实时上传到服务器。我NSURLSession
与NSURLSessionUploadTask
created using一起使用[NSURLSession uploadTaskWithRequest:myRequest fromFile:fileURL]
将数据发送到服务器。
现在,该应用程序在后台按预期工作了 4-5 小时,但之后 iOS 会终止该应用程序。
这是崩溃日志。
Date/Time: 2014-04-02 19:32:11.694 -0700
OS Version: iOS 7.0.4 (11B554a)
Report Version: 104
Exception Type: 00000020
Exception Codes: 0x000000008badf00d
Highlighted Thread: 2
Application Specific Information:
MyApp[2548] has active assertions beyond permitted time:
{(
<BKProcessAssertion: 0x15d83310> identifier: Background Content Fetching (66) process: MyApp[2548] permittedBackgroundDuration: 30.000000 reason: backgroundContentFetching owner pid:33 preventSuspend preventThrottleDownUI preventIdleSleep preventSuspendOnSleep
)}
Elapsed total CPU time (seconds): 1.300 (user 1.300, system 0.000), 2% CPU
Elapsed application CPU time (seconds): 0.029, 0% CPU
Thread 0:
0 libsystem_kernel.dylib 0x3bb18a8c mach_msg_trap + 20
1 libsystem_kernel.dylib 0x3bb18888 mach_msg + 44
2 CoreFoundation 0x30c957be __CFRunLoopServiceMachPort + 150
3 CoreFoundation 0x30c93f2a __CFRunLoopRun + 850
4 CoreFoundation 0x30bfec22 CFRunLoopRunSpecific + 518
5 CoreFoundation 0x30bfea06 CFRunLoopRunInMode + 102
6 GraphicsServices 0x358ff27e GSEventRunModal + 134
7 UIKit 0x334a2044 UIApplicationMain + 1132
8 MyApp 0x0007b8b8 main (main.m:16)
9 libdyld.dylib 0x3ba74ab4 start + 0
Thread 1:
0 libsystem_kernel.dylib 0x3bb1883c kevent64 + 24
1 libdispatch.dylib 0x3ba59210 _dispatch_mgr_invoke + 228
2 libdispatch.dylib 0x3ba58f96 _dispatch_mgr_thread$VARIANT$mp + 34
Thread 2 name: com.apple.NSURLConnectionLoader
Thread 2:
0 libsystem_kernel.dylib 0x3bb18a8c mach_msg_trap + 20
1 libsystem_kernel.dylib 0x3bb18888 mach_msg + 44
2 CoreFoundation 0x30c957be __CFRunLoopServiceMachPort + 150
3 CoreFoundation 0x30c93ee4 __CFRunLoopRun + 780
4 CoreFoundation 0x30bfec22 CFRunLoopRunSpecific + 518
5 CoreFoundation 0x30bfea06 CFRunLoopRunInMode + 102
6 Foundation 0x316392f2 +[NSURLConnection(Loader) _resourceLoadLoop:] + 314
7 Foundation 0x316aec82 __NSThread__main__ + 1058
8 libsystem_pthread.dylib 0x3bb93c1a _pthread_body + 138
9 libsystem_pthread.dylib 0x3bb93b8a _pthread_start + 98
10 libsystem_pthread.dylib 0x3bb91c8c thread_start + 4
Thread 3 name: com.apple.CFSocket.private
Thread 3:
0 libsystem_kernel.dylib 0x3bb2b440 __select + 20
1 CoreFoundation 0x30c99680 __CFSocketManager + 480
2 libsystem_pthread.dylib 0x3bb93c1a _pthread_body + 138
3 libsystem_pthread.dylib 0x3bb93b8a _pthread_start + 98
4 libsystem_pthread.dylib 0x3bb91c8c thread_start + 4
Thread 4:
0 libsystem_kernel.dylib 0x3bb2bc7c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x3bb91dc6 _pthread_wqthread + 306
2 libsystem_pthread.dylib 0x3bb91c80 start_wqthread + 4
我没有在 中实现[UIApplicationDelegate application:performFetchWithCompletionHandler:]
方法AppDelegate
,因为我认为这与后台下载有关。
为什么我的应用程序在使用NSURLSession
后台配置时会崩溃?这与不实施有关[UIApplicationDelegate application:performFetchWithCompletionHandler:]
吗?
谢谢。