2017-08-28 37 views
0

我有一个连接到OneSignal的离子安卓应用程序,以及通过我的WordPress网站发布帖子的WordPress。我安装了OneSignal插件,并将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

人们可能不会阅读外部来源的代码。请将相关部分添加到您的帖子中。 – RealCheeseLord

+0

改进的英文,格式,添加了php标签 –

回答

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; 
} 
相关问题