Nativescript - Onesignal 休息 Api

Nativescript - Onesignal rest Api

我在我的应用程序上使用 onesignal sdk 推送通知,但我很难理解我如何发送一个大图标,我的意思是当用户收到推送时留在左边的那个(而不是显示铃铛)...我知道图标必须是透明的并且有 256px x 256px。我使用其余 api 发送推送,但我不知道问题出在哪里,因为似乎没有任何效果,这是我的代码:

public function sendMessage($messagePush){
        $subtitle=["en" => $messagePush['message']];
        $content      = array(
            "en" => $messagePush['contentJson']['tipoImovel'],
            "large_icon" => public_path('img/icon.png')
        );
        $hashes_array = array();
        array_push($hashes_array, array(
            "id" => "id1",
            "text" => "Ver"
        ));
        $fields = array(
            'app_id' => "myappid",
            'included_segments' => array(
                'All'
            ),
            'data' => array(
                "imovel" => $messagePush['contentJson']
            ),
            'headings'=> $subtitle,
            'contents' => $content,
            'buttons' => $hashes_array
        );

        $fields = json_encode($fields);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json; charset=utf-8',
            'Authorization: my autorization'
        ));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

        $resp = curl_exec($ch);
        curl_close($ch);

        return $resp;
    }

我可以收到推送,但图标永远不会出现,还有另一个问题......推送总是出现在顶部托盘而不是弹出窗口"kind",下面的方式是还有我的 app.js:

上的代码
if (application.android) {
    application.on(application.launchEvent, (args) => {
        try {
            TnsOneSignal.startInit(application.android.context).setNotificationOpenedHandler(new TnsOneSignal.NotificationOpenedHandler({
                // notificationOpened: function (result: com.onesignal.OSNotificationOpenResult) {
                notificationOpened: function (result) {
                    const imovelAndroid =  JSON.parse(result.stringify()).notification.payload.additionalData;
                    handleOpenURL(imovelAndroid);
                }
            })).init();
            TnsOneSignal.setInFocusDisplaying(TnsOneSignal.OSInFocusDisplayOption.Notification);
            TnsOneSignal.startInit(application.android.context).init();
        }
        catch (error) {
            console.error('error', error);
        }
    });
}

如果我删除 TnsOneSignal.setInFocusDisplaying(TnsOneSignal.OSInFocusDisplayOption.Notification); 弹出样式出现,但按钮不导航到我的 handleOpenURL 功能...但如果我让它保留,它会导航,但推送始终在托盘上。

有什么建议吗?谢谢你的时间。 此致

您必须删除 TnsOneSignal.setInFocusDisplaying(TnsOneSignal.OSInFocusDisplayOption.Notification);,因为这会强制通知成为托盘一。默认一个已经是InAppAlert

您在第二次调用 startInit 时重置了 setNotificationOpenedHandler。因此,如果您也删除第二个 startInit 语句,您应该会很好。