Skip to content

Instantly share code, notes, and snippets.

@quangtqag
quangtqag / AppDelegate.swift
Last active August 31, 2023 02:15
Make app always call applicationWillTerminate
func applicationDidEnterBackground(application: UIApplication) {
// Create a pseudo background task to system call applicationWillTerminate when app enter background
// Default system will not call applicationWillTerminate when app enter background
// applicationWillTerminate only called when user close app in app switcher or some special cases of system
bgTask = application.beginBackgroundTaskWithExpirationHandler({ () -> Void in
application.endBackgroundTask(self.bgTask)
self.bgTask = UIBackgroundTaskInvalid
})
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { () -> Void in
/*
* Copyright (C) 2016 Evan Halley
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software