Created
April 10, 2020 14:51
-
-
Save imtoori/f95b30f25b745c5f777bfff1085176ef to your computer and use it in GitHub Desktop.
AppDelegate template to configure push notification and offline storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Flutter | |
@UIApplicationMain | |
@objc class AppDelegate: FlutterAppDelegate { | |
let sharedDefaults = UserDefaults(suiteName: APPGROUP) | |
override func application( | |
_ application: UIApplication, | |
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? | |
) -> Bool { | |
if let messageQueue = sharedDefaults?.stringArray(forKey: "messageQueue") { | |
UserDefaults.standard.setValue(messageQueue, forKey: "flutter.messageQueue") | |
sharedDefaults?.removeObject(forKey: "messageQueue") | |
} | |
GeneratedPluginRegistrant.register(with: self) | |
return super.application(application, didFinishLaunchingWithOptions: launchOptions) | |
} | |
override func applicationDidEnterBackground(_ application: UIApplication) { | |
if let apiKey = UserDefaults.standard.string(forKey: "flutter.KEY_API_KEY") { | |
sharedDefaults?.setValue(apiKey, forKey: "KEY_API_KEY") | |
} | |
if let token = UserDefaults.standard.string(forKey: "flutter.KEY_TOKEN") { | |
sharedDefaults?.setValue(token, forKey: "KEY_TOKEN") | |
} | |
if let userId = UserDefaults.standard.string(forKey: "flutter.KEY_USER_ID") { | |
sharedDefaults?.setValue(userId, forKey: "KEY_USER_ID") | |
} | |
} | |
override func applicationWillEnterForeground(_ application: UIApplication) { | |
if let messageQueue = sharedDefaults?.stringArray(forKey: "messageQueue") { | |
UserDefaults.standard.setValue(messageQueue, forKey: "flutter.messageQueue") | |
sharedDefaults?.removeObject(forKey: "messageQueue") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment