在 Cordova 中处理 SMS 通知

improve this page | report issue


概述

SMS 通知是推送通知的一个子集,因此请务必先阅读在 Cordova 中查看推送通知教程。
iOS 和 Android 都支持 Cordova 应用程序中的 SMS 通知。

先决条件:

跳转至:

通知 API

在 SMS 通知中,当注册设备时,将传递电话号码值。

注册设备

向推送通知服务注册设备。

MFPPush.registerNotificationsCallback(notificationReceived);

function registerDevice() {
    var phoneNumber = prompt("Enter Your 10 digit phone number");
    if(phoneNumber != null &&  phoneNumber!="" &&  /^\d+$/.test(phoneNumber)) {
        var options = {};
        options.phoneNumber = phoneNumber;
        MFPPush.registerDevice(options,
        function(successResponse) {
            alert("Successfully registered");
            enableButtons();
        }, function(failureResponse) {
            alert("Failed to register");
        });
        return true;
    }

    else {
        alert("Failed to register, You have entered invalid number");
    }
}

也可以使用推送设备注册 (POST) REST API 来注册设备

使用 SMS 预订 servlet

可使用 REST API 将通知发送到已注册的设备。 可以发送所有形式的通知:标记通知、广播通知和已认证的通知

要发送通知,可使用 POST 向 REST 端点发出请求:imfpush/v1/apps/<application-identifier>/messages
示例 URL:

https://myserver.com:443/imfpush/v1/apps/com.sample.sms/messages

要查看所有推送通知 REST API,请参阅用户文档中的 REST API 运行时服务主题。

要发送通知,请参阅发送通知教程。

样本应用程序图像

样本应用程序

单击以下载 Cordova 项目。

注:要运行此样本,需要在任何 Android 设备上安装最新版本的 Google Play Services。

用法样例

请查看样本的 README.md 文件以获取指示信息。

Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on June 01, 2020