Ich habe den folgenden Code, der einen Anruf an den Server macht, bevor die App beendet wird. Mein Problem ist, dass der Code manchmal funktioniert, manchmal nicht. Meistens nicht. Hier ist der Code:backgroundTask nicht in iOS fertig
//Set the user as in-active if app is force closed
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
NSLog(@"called");
bgTask = [application beginBackgroundTaskWithName:@"setInActive" expirationHandler:^{
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"disp called");
//If the app is about to exit make the user inactive
[[APIManager sharedInstance] setInActiveOnCompletion:^(BOOL finished){
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
});
}
Der erste NSLog wird jedes Mal aufgerufen. Die zweite jedoch nicht. Es scheint, als ob die App nicht einmal in die dispatch_async
Methode geht.
EDIT: Also im Grunde alles, was ich tun muss, ist dem Server zu sagen, dass ein Benutzer die App beendet hat, während dieser Benutzer angemeldet war. Wie könnte ich das tun?
Irgendwelche Ideen?