我有一个连接到OneSignal的离子安卓应用程序,以及我通过我的WordPress网站发布帖子的WordPress。我安装了OneSignal插件,并将Onesignal提供的自定义代码仅发送到移动应用程序而不是浏览器。但是,当我点击通知时,它会将我带到网络而不是应用程序。
以下代码仅用于向移动应用发送通知。当我使用这段代码时,我会收到通知,但它会将我带到网上。代码粘贴在their documentation下面。
<?php
function onesignal_send_notification_filter($fields, $new_status, $old_status, $post)
{
$fields['isAndroid'] = true;
$fields['isIos'] = true;
$fields['isAnyWeb'] = false;
$fields['isChrome'] = false;
$fields['data'] = array(
"myappurl" => $fields['url']
);
/* Unset the URL to prevent opening the browser when the notification is clicked */
unset($fields['url']);
return $fields;
}
答案 0 :(得分:0)
试试这个。
<?php
add_filter('onesignal_send_notification', 'onesignal_send_notification_filter', 10, 4);
function onesignal_send_notification_filter($fields, $new_status, $old_status, $post)
{
$fields = $fields;
$fields['isAndroid'] = true;
$fields['isIos'] = true;
$fields['isAnyWeb'] = false;
$fields['isWP'] = false;
$fields['isAdm'] = false;
$fields['isChrome'] = false;
$fields['data'] = array(
"myappurl" => $fields['url']
);
/* Unset the URL to prevent opening the browser when the notification is clicked */
unset($fields['url']);
return $fields;
}