Push notification not receiving in background iOS

后端 未结 3 923
情深已故
情深已故 2020-12-07 05:31

I am doing push notification in my project through GCM. My Application is able to receive notification in foreground but not in background.

I receive a message insi

相关标签:
3条回答
  • 2020-12-07 05:50

    Create notification in this pattern

    {
        "to": "ID",
        "notification": {
            "sound": "default",
            "title": "TITLE",
            "body": "BODY"
        },
        "priority": "high"
    }
    
    0 讨论(0)
  • 2020-12-07 06:02

    For ones who are dealing with Pushy instead of GSM, pushy's completion handler might not get called when app is in background because of this:

    Even though you configure notification payload with propriate keys and values such as for example:

    {"to":"device***Token", "data": {"message": "Hello World!"}, "notification": {"title": "test", "body": "my message"}, "content_available": true}
    

    and send it using Pushy's Console, it happens that all these data are placed in pushy's site field: 'NOTIFICATION DATA'. So using Console we found no way to send: true, for key: "content_available" which is necceserry to involve handler when app is in background.

    You can get out of this by using Postman for instance, configuring your request as this:

    1. type: POST;
    2. raw;
    3. url: https://api.pushy.me/push?api_key=YOUR_APP_API_KEY;
    4. Content-Type: application/json;

    And in body place something you need to send, for example:

     {"data":{"message": "Hello World!"},"tokens":["device***Token"],"content_available": true}
    

    With this, you'll place "content_available" key inside "aps" and not inside "data", which will call your handler while app is in background.

    0 讨论(0)
  • 2020-12-07 06:09

    use this payload

    {
        "aps": {
            "alert": "Hello World",
            "sound": "default"
            "content-available" :1
        }
    }
    

    With content-available enabled:

    1 App is in Foreground

    No system alert shown

    application:didReceiveRemoteNotification:fetchCompletionHandler: is called

    2 App is in Background

    System alert is shown

    application:didReceiveRemoteNotification:fetchCompletionHandler: is called

    3App is in Suspended

    App state changes to Background

    System alert is shown

    application:didReceiveRemoteNotification:fetchCompletionHandler: is called

    4 App is Not Running because killed by user

    System alert is shown

    No callback is called

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