3

crash report detail :

Hardware Model:      iPhone5,2
Exception Type:  00000020
Exception Codes: 0x000000008badf00d
Highlighted Thread:  3

Application Specific Information:
MyApp[1369] has active assertions beyond permitted time: 
{(
<BKProcessAssertion: 0x175ca7d0> identifier: Called by MyApp, from -[AppDelegate applicationDidEnterBackground:] process: MyApp[1369] permittedBackgroundDuration: 180.000000 reason: finishTask owner pid:1369 preventSuspend  preventIdleSleep      preventSuspendOnSleep 
)}

thread 3 :

Thread 3 name:  com.apple.NSURLConnectionLoader
Thread 3:
0   libsystem_kernel.dylib          0x3937ea50 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x3937e848 mach_msg + 36
2   CoreFoundation                  0x2e61261c __CFRunLoopServiceMachPort + 152
3   CoreFoundation                  0x2e610d3c __CFRunLoopRun + 788
4   CoreFoundation                  0x2e57b7a4 CFRunLoopRunSpecific + 520
5   CoreFoundation                  0x2e57b586 CFRunLoopRunInMode + 102
6   Foundation                      0x2efbb23c +[NSURLConnection(Loader)     _resourceLoadLoop:] + 316
7   Foundation                      0x2f030a0a __NSThread__main__ + 1058
8   libsystem_pthread.dylib         0x393f8956 _pthread_body + 138
9   libsystem_pthread.dylib         0x393f88c6 _pthread_start + 98
10  libsystem_pthread.dylib         0x393f6ae4 thread_start + 4

my app using background task with this code at "applicationDidEnterBackground" :

// 10min background task
UIBackgroundTaskIdentifier myLongTask;
myLongTask = [[UIApplication sharedApplication]
              beginBackgroundTaskWithExpirationHandler:^{
                  [locationMgrInstance timerSet];
              }];
// cell change  
[locationMgrInstance startMonitoringSignificantLocationChanges];

it works good at iOS 6... but! iOS 7 throw assert after 180 sec. help!

jake85
  • 31
  • 1
  • 3

1 Answers1

11

This message indicates that your background task ran for too long. iOS7 has changed some aspects of background processing. In particular a background task should complete in a short amount of time and if it doesn't your app is terminated. You need to look at how your background tasks are operating. In particular, you need to ensure that you call [[UIApplication sharedApplication] endBackgroundTask:task]; in a timely manner. You should also call this method in your expiration handler.

Have a look at the Background Execution and Multitasking section in the Apple iOS App Programming Guide Background Execution Guide.

Additionally, you can check [[UIApplication sharedApplication]backgroundTimeRemaining] - on iOS 6 this started at 10 minutes. In iOS 7 it starts at 3 minutes - which is why you are getting timed out after 180 seconds. You need to re-evaluate your background strategy to deal with the new limit.

holex
  • 23,961
  • 7
  • 62
  • 76
Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • thanks, but i still doubtful that... when i use that code (beginBackgroundTaskWithExpirationHandler), application called every minute until 10 minutes. – jake85 Mar 27 '14 at 08:39
  • But where in your code are you calling endBackgroundTask? – Paulw11 Mar 27 '14 at 09:00
  • oh! i'm not call that methods... is it mean my case? – jake85 Mar 27 '14 at 09:06
  • Well you should call that method when you have completed your work, otherwise the OS thinks you are still active, but see my update to my answer - you only have 3 minutes to complete your work under iOS7 while previously you had 10. – Paulw11 Mar 27 '14 at 09:10
  • yes! i call 10 minutes, when i remove this code "startMonitoringSignificantLocationChanges" it still work! – jake85 Mar 27 '14 at 09:12
  • Significant location change notification is separate to a background task. A background task is, for example, if you needed to complete some work such as saving your data to a server. If you register for significant location change then your app will receive the notifications without you needing a background task – Paulw11 Mar 27 '14 at 09:15
  • is there any way to achieve the upload operation in the background which will take more than 3 minutes – Raghav Oct 27 '15 at 12:25
  • You can use NSURLSession https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH4-SW5 https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSession_class/ – Paulw11 Oct 27 '15 at 12:32