Ziad Alame
Ziad Alame

Reputation: 772

Notification action buttons not appearing on iOS and android using one signal react-native-onsignal

I'm trying to send notifications with action buttons. The notifications arrive and work perfectly - however actions do not appear on either android (7.0) or iOS (11.2.1)

I am sending this body with the post request to https://onesignal.com/api/v1/notifications | I even tried the OS UI dashboard tool and nothing worked.

{
    "app_id": "#########-#########-########",
    "heading": "OneSignal Web Push Notification",
    "contents": {
        "en": "Action buttons increase the ways your users can interact with your notification."
    },
    "data": {
        "notificationType": "news-feature"
    },
    "url": "https://example.com",
    "icon": "https://onesignal.com/images/notification_logo.png",
    "buttons": [
        {
            "action": "like-button",
            "title": "Like",
            "icon": "http://i.imgur.com/N8SN8ZS.png",
            "url": "https://example.com"
        },
        {
            "action": "read-more-button",
            "title": "Read more",
            "icon": "http://i.imgur.com/MIxJp1L.png",
            "url": "https://example.com"
        }
    ],
    "action": "like-button",
    "include_player_ids": [
        "######-###################-#####", //iOS ID
        "######-###################-#####", // android ID
    ]
}

Any thoughts or suggestions on how to solve or debug this?

Upvotes: 1

Views: 2085

Answers (1)

Ziad Alame
Ziad Alame

Reputation: 772

Setting up the OneSignalNotificationServiceExtension in order for buttons (as well as images, etc) to appear in push notifications fixed the problem.

iOS Xcode Project guide is helpful in this matter:

https://github.com/Nightsd01/react-native-onesignal#add-notification-service-extension

A small pointer to skip the part where you have to pod install the onesignal pod for the app target. Just install the ServiceExtension pod.


For Android updating the payload of the buttons object in the POST request fixed the problem. { "app_id": "######-###################-#####", "heading": "OneSignal Web Push Notification", "contents": { "en": "Action buttons increase the ways your users can interact with your notification." }, "data": { "notificationType": "news-feature" }, "url": "https://example.com", "icon": "https://onesignal.com/images/notification_logo.png", "buttons":[ {"id": "id1", "text": "button1", "icon": "ic_launcher"}, {"id": "id2", "text": "button2", "icon": "ic_launcher"} ], "action": "like-button", "include_player_ids": [ "######-###################-#####", // iOS ID "######-###################-#####" // android ID ] }

Upvotes: 1

Related Questions