I have an application that stores the user\'s session in NSUserDefaults. When the application is forced to close, in the initial verify whether the data controller user sess
Here is the solution,
First Upload the necessary certificates in Firebase Console Then in your app enable Push Notifications and Background Modes -> Remote Notifications
After that in App Delegate use the code below(I specify the tricky line) :
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
registerForPushNotifications(application)
// Override point for customization after application launch.
// Use Firebase library to configure APIs
FIRApp.configure()
return true
}
func registerForPushNotifications(application: UIApplication) {
let notificationSettings = UIUserNotificationSettings(
forTypes: [.Badge, .Sound, .Alert], categories: nil)
application.registerUserNotificationSettings(notificationSettings)
}
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
if notificationSettings.types != .None {
application.registerForRemoteNotifications()
}
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let tokenChars = UnsafePointer(deviceToken.bytes)
var tokenString = ""
for i in 0..