How to store ios push notifications when the app is killed using swift

前端 未结 1 885
既然无缘
既然无缘 2020-12-22 03:29

I use my own server, use FCM to push notifications to the ios device, push notifications are successful, I also use the Realm database system to help me store the fcm push n

相关标签:
1条回答
  • 2020-12-22 04:00

    You can store notifications into your database when your app is killed.

    1. Add "Notification Service Extention" to your app.
    2. Enable Background fetch/Remote notifications Capabilities into your app.
    3. Enable "App Groups" into your app and enable the same with your "Notification Service Extention".

    1. Now you can access your database using "App Groups", and can insert notifications into your database as soon as you receive the notification.

    To access database using "App Group" use,

    var fileMgr : FileManager!
    let databasePathURL = fileMgr!.containerURL(forSecurityApplicationGroupIdentifier: "<APP_GROUPS_ID>")
    

    From above code once you get the path for database, you can perform your insert operation into database. It would be your normal insert operation that you are performing.

    Insert code for saving data in this file and in the method highlighted in below image.

    For accessing your files into Extention follow the below image.

    If you need any other help, Do let me know.

    0 讨论(0)
提交回复
热议问题