I have created an app which tracks the location of the user even if the app is in the background or the screen is locked. I have tested it on an iPhone 5s device with iOS 9.2 and everything was working fine. After updating to iOS 9.3.1 I noticed that the app would run for about 10 minutes in the background and then app would automatically stop. I updated the phone to iOS 9.3.2 yesterday hoping that there was a fix for this issue. However the issue still persists.
I have the following code in AppDelegate class
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
private static var backgroundService : BackgroundService? = nil
var startServices : Bool = false
public static var bgTask = UIBackgroundTaskIdentifier()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
print("didFinishLaunchingWithOptions")
AppDelegate.bgTask = beginBackgroundUpdateTask()
startBackgroundService()
return true
}
internal func startBackgroundService(){
if AppDelegate.backgroundService == nil{
AppDelegate.backgroundService = BackgroundService.getBackgroundService()
}
AppDelegate.backgroundService!.startService(self)
}
internal func stopBackgroundService(){
AppDelegate.backgroundService!.stopService()
}
func beginBackgroundUpdateTask() -> UIBackgroundTaskIdentifier {
return UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler({})
}
func applicationDidEnterBackground(application: UIApplication) {
self.startBackgroundService()
print("applicationDidEnterBackground")
}
}
Background App Refresh and Location Services have been enabled for the app on the iphone. Background mode has been enabled and other required permissions have been added in Info.plist.
The issue is not due to any code changes as I tested the code on another phone with iOS 9.2 and it is working perfectly. After updating the second phone to iOS 9.3.2 the same issue occurred. Has there been any change in 9.3 which is causing this issue? I went through the changelogs and documentation but haven't been able to find anything useful. Has anyone else encountered a similar issue? Is there any changes that I need to do to ensure that the app works with iOS 9.3?