Bucket
Bucket

Reputation: 449

How to save remote notification data into Core Data(Database) from NotificationServiceExtension

I have implemented NotificationServiceExtension in my target application, and it is working fine.

Upvotes: 7

Views: 1993

Answers (1)

Jayachandra A
Jayachandra A

Reputation: 1342

Try adding the following code to your AppDelegate class and test it.

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    completionHandler(.newData)
    performSelector(inBackground: #selector(saveNewNotificationInBackground(userInfo:)), with: userInfo)
}

@objc func saveNewNotificationInBackground(userInfo: [AnyHashable: Any]) -> Void {
    //save notification using core data
}

Upvotes: 6

Related Questions