【问题标题】:How to make onesignal plugin send notification only to mobile app?如何使onesignal插件仅向移动应用程序发送通知?
【发布时间】:2017-08-28 08:14:56
【问题描述】:

我有一个连接到 OneSignal 的 ionic android 应用程序和 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;
}

【问题讨论】:

  • 人们可能不会阅读外部来源的代码。请在您的帖子中添加相关部分。
  • 改进了英文、格式、添加了 php 标签

标签: php wordpress ionic-framework web-applications onesignal


【解决方案1】:

试试这个。

<?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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多