Nativescript - Onesignal休息Api

问题描述 投票:0回答:1

我在我的应用程序上使用onesignal sdk推送通知,但我有理解我怎么能用大图标发送,我的意思是当用户收到推送时(而不是显示铃声)留在左侧的那个。 ..i知道图标必须是透明的,并且具有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;
    }

我可以接受推送,但图标永远不会出现,还有另一个问题......推送总是出现在顶部托盘上而不是弹出式“亲切”,因为下面这种方式也是我的代码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);弹出式样式出现,但按钮没有navegate到我的handleOpenURL函数...但如果我让它保持,它确实导航但推送始终在托盘上。

有小费吗?谢谢你的时间。问候

nativescript onesignal
1个回答
1
投票

您将不得不删除TnsOneSignal.setInFocusDisplaying(TnsOneSignal.OSInFocusDisplayOption.Notification);,因为这将强制通知为托盘之一。默认的一个是InAppAlert

你在第二次打电话给setNotificationOpenedHandler时重置了startInit。因此,如果你删除第二个startInit声明,你应该是好的。

© www.soinside.com 2019 - 2024. All rights reserved.