acmPush模塊示例demo

感謝論壇版主 馬浩川 的分享。

模塊介紹: 
阿里移動推送(Alibaba Cloud Mobile Push)是基於大數據的移動智能推送服務,幫助App快速集成移動推送的功能,在實現高效、精確、實時的移動推送的同時,極大地降低了開發成本。讓開發者最有效地與用戶保持連接,從而提高用戶活躍度、提高應用的留存率。

EMAS操作圖示:
創建 , 在這裏獲取配置項的值

acmPush模塊示例demo
acmPush模塊示例demo
配置ios推送證書:
acmPush模塊示例demo
開發環境下需要填寫單個設備id
acmPush模塊示例demo
消息通知: 需要打開消息監聽addMessageListener
acmPush模塊示例demo
記錄: 
acmPush模塊示例demo
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
<title>Hello APP</title>
<link rel="stylesheet" type="text/css" href="../css/api.css" />
<style>
label {
margin: 10px;
font-size: 24px;
}

    ul {
        margin-bottom: 10px;
    }

    ul li {
        margin: 5px 10px;
        padding: 5px;
        color: #000;
        word-wrap: break-word;
    }

    button {
        font-size: 18px;
        display: block;
        padding: 10px;
    }

</style>
</head>

<body>
<button>統計App啓動信息(android)</button>
<button>添加消息監聽</button>
<button>移除消息監聽</button>
<button>獲取設備唯一標識</button>
<button>打開推送通道(android)</button>
<button>關閉推送通道(android)</button>
<button>查詢通道狀態</button>
<button>綁定標籤</button>
<button>本設備標籤查詢</button>
<button>設備添加別名</button>
<button>設置通知聲音</button>
<button>設置通知欄圖標</button>
<button>設置免打擾時段</button>
<button>關閉免打擾</button>
<button>刪除所有通知</button>
<button>同步角標數到服務端</button>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
var acmPush;
apiready = function() {
acmPush = api.require('acmPush');
};

function getDeviceId() {
    acmPush.getDeviceId({}, function(ret, err) {
        console.log(JSON.stringify(ret));
    });
}

function addMessageListener() {
    acmPush.addMessageListener({
        listenerName: 'name',
    }, function(ret, err) {
        alert(JSON.stringify(ret));
    });
}

function onAppStart() {
    acmPush.onAppStart({}, function(ret, err) {
        alert(JSON.stringify(ret));
    });
}

function turnOnPushChannel() {
    acmPush.turnOnPushChannel({}, function(ret, err) {
        alert(JSON.stringify(ret));
    });
}

function turnOffPushChannel() {
    acmPush.turnOffPushChannel({}, function(ret, err) {
        alert(JSON.stringify(ret));
    });
}

function checkPushChannelStatus() {
    acmPush.checkPushChannelStatus({}, function(ret, err) {
        alert(JSON.stringify(ret));
    });
}

function bindTag() {
    acmPush.bindTag({
        target: 1,
        tags: ["Google", "Runoob", "Taobao"],
    }, function(ret, err) {
        alert(JSON.stringify(ret));
    });
}

function listTags() {
    acmPush.listTags({}, function(ret, err) {
        alert(JSON.stringify(ret));
    });
}

function addAlias() {
    acmPush.addAlias({
        alias: '別名1',
    }, function(ret, err) {
        alert(JSON.stringify(ret));
    });
}

function setNotificationSound() {
    acmPush.setNotificationSound({
        soundPath: 'widget://res/sound.mp3',
    }, function(ret, err) {
        alert(JSON.stringify(ret));
    });
}

function setNotificationLargeIcon() {
    acmPush.setNotificationLargeIcon({
        iconPath: 'widget://res/QQ.png',
    }, function(ret, err) {
        alert(JSON.stringify(ret));
    });
}

function setDoNotDisturb() {
    acmPush.setDoNotDisturb({
        startHour: 0,
        startMinute: 02,
        endHour: 1,
        endMinute: 02
    }, function(ret, err) {
        alert(JSON.stringify(ret));
    });
}

function closeDoNotDisturbMode() {
    acmPush.closeDoNotDisturbMode({}, function(ret, err) {
        alert(JSON.stringify(ret));
    });
}

function clearNotifications() {
    acmPush.clearNotifications({}, function(ret, err) {
        alert(JSON.stringify(ret));
    });
}
function syncBadgeNum() {
    acmPush.syncBadgeNum({
        num: 1,
    }, function(ret, err) {
        alert(JSON.stringify(ret));
    });
}

</script>

</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章