urbanairship/ios-library — pull request #61 by stefanprutianu (2014-07-10 11:39:31+00:00)
Title: mark background task as ended when OS calls the expiration handler

According to documentation the expiration handler for -[UIApplication beginBackgroundTaskWithExpirationHandler:] must explicitly mark the task as ended via - [UIApplication endBackgroundTask:] when the OS decided to call the expiration handler.

There is a situation where a request for creating a channel (/api/channels/) fails and a retry is scheduled for after 300 sec thus the failure block is not called and the background task is never marked as ended. On iOS7 the maximum allowed time for running in background is ~3 min which means that the expiration handler is called before channel creation request retrial. Failure to mark the task as ended results in a crash.

has active assertions beyond permitted time:
{(
identifier: Called by , from -[UAPush beginRegistrationBackgroundTask] process: [183] permittedBackgroundDuration: 180.000000 reason: finishTask owner pid:183 preventSuspend preventIdleSleep preventSuspendOnSleep
)}
Forcing crash report of ...

Reproducing the channel creation request failure is not always easy but when it happens this should fix the problem.