เอกสารอ้างอิง API ของปลั๊กอิน Cordova
var pushwoosh = cordova.require("pushwoosh-cordova-plugin.PushNotification");
// Should be called before pushwoosh.onDeviceReadydocument.addEventListener('push-notification', function(event) { var notification = event.notification; // handle push open here});
// Initialize Pushwoosh. This will trigger all pending push notifications on start.pushwoosh.onDeviceReady({ appid: "XXXXX-XXXXX", serviceName: "XXXX"});
pushwoosh.registerDevice( function(status) { var pushToken = status.pushToken; // handle successful registration here }, function(status) { // handle registration error here });onDeviceReady
Anchor link toPushNotification.prototype.onDeviceReady = function( config )[android, ios, wp8, windows]
เริ่มต้นปลั๊กอิน Pushwoosh และทริกเกอร์ข้อความพุชเริ่มต้น ควรเรียกใช้ทุกครั้งที่เปิดแอป
config.appid – รหัสแอปพลิเคชัน Pushwoosh
config.serviceName – ชื่อบริการ MPNS สำหรับแพลตฟอร์ม wp8
// initialize Pushwoosh with appid : "PUSHWOOSH_APP_ID", serviceName : "WINDOWS_PHONE_SERVICE". This will trigger all pending push notifications on start.pushwoosh.onDeviceReady({ appid : "XXXXX-XXXXX", serviceName: "XXXX"});registerDevice
Anchor link toPushNotification.prototype.registerDevice = function( success, fail )[android, ios, wp8, windows]
ลงทะเบียนอุปกรณ์สำหรับการแจ้งเตือนแบบพุชและดึงข้อมูลพุชโทเค็น
success – คอลแบ็กเมื่อสำเร็จ พุชโทเค็นจะถูกส่งเป็นพารามิเตอร์ “status.pushToken” ไปยังคอลแบ็กนี้
fail – คอลแบ็กเมื่อเกิดข้อผิดพลาด
pushwoosh.registerDevice( function(status) { alert("Registered with push token: " + status.pushToken); }, function(error) { alert("Failed to register: " + error); });unregisterDevice
Anchor link toPushNotification.prototype.unregisterDevice = function( success, fail )[android, ios, wp8, windows]
ยกเลิกการลงทะเบียนอุปกรณ์จากการรับการแจ้งเตือนแบบพุช
success – คอลแบ็กเมื่อสำเร็จ
fail – คอลแบ็กเมื่อเกิดข้อผิดพลาด
setTags
Anchor link toPushNotification.prototype.setTags = function( config, success, fail )[android, ios, wp8, windows]
ตั้งค่าแท็กสำหรับอุปกรณ์
พารามิเตอร์
config – อ็อบเจกต์ที่มีแท็กอุปกรณ์แบบกำหนดเอง
success – คอลแบ็กเมื่อสำเร็จ พุชโทเค็นจะถูกส่งเป็นพารามิเตอร์ “status.pushToken” ไปยังคอลแบ็กนี้
fail – คอลแบ็กเมื่อเกิดข้อผิดพลาด
// sets tags: “deviceName” with value “hello” and “deviceId” with value 10pushwoosh.setTags({deviceName:"hello", deviceId:10}, function() { console.warn('setTags success'); }, function(error) { console.warn('setTags failed'); });
// sets list tags "MyTag" with values (array) "hello", "world"pushwoosh.setTags({"MyTag":["hello", "world"]});getTags
Anchor link toPushNotification.prototype.getTags = function( success, fail )[android, ios, wp8, windows]
ส่งคืนแท็กสำหรับอุปกรณ์รวมถึงแท็กเริ่มต้น
success – คอลแบ็กเมื่อสำเร็จ รับแท็กเป็นพารามิเตอร์
fail – คอลแบ็กเมื่อเกิดข้อผิดพลาด
pushwoosh.getTags( function(tags) { console.warn('tags for the device: ' + JSON.stringify(tags)); }, function(error) { console.warn('get tags error: ' + JSON.stringify(error)); });getPushToken
Anchor link toPushNotification.prototype.getPushToken = function( success )[android, ios, wp8, windows]
ส่งคืนพุชโทเค็นหากมีอยู่ โปรดทราบว่าโทเค็นยังมาในคอลแบ็กของฟังก์ชัน registerDevice ด้วย
success – คอลแบ็กเมื่อสำเร็จ
pushwoosh.getPushToken( function(token) { console.warn('push token: ' + token); });getPushwooshHWID
Anchor link toPushNotification.prototype.getPushwooshHWID = function( success )[android, ios, wp8, windows]
ส่งคืน Pushwoosh HWID ที่ใช้สำหรับการสื่อสารกับ Pushwoosh API
success – คอลแบ็กของ getPushwooshHWID
pushwoosh.getPushwooshHWID( function(token) { console.warn('Pushwoosh HWID: ' + token); });getRemoteNotificationStatus
Anchor link toPushNotification.prototype.getRemoteNotificationStatus = function( callback, error )[android, ios]
ส่งคืนสถานะโดยละเอียดของสิทธิ์การแจ้งเตือนแบบพุช
callback – คอลแบ็กเมื่อสำเร็จ รับอ็อบเจกต์ที่มีคุณสมบัติดังต่อไปนี้:
{ "enabled" : notificaions enabled flag. "pushBadge" : badges permission granted. (iOS only) "pushAlert" : alert permission granted. (iOS only) "pushSound" : sound permission granted. (iOS only)}error — คอลแบ็กเมื่อเกิดข้อผิดพลาด
setApplicationIconBadgeNumber
Anchor link toPushNotification.prototype.setApplicationIconBadgeNumber = function( badgeNumber )[android, ios]
ตั้งค่าหมายเลขแบจบนไอคอนแอปพลิเคชัน
badgeNumber – หมายเลขแบจบนไอคอน
getApplicationIconBadgeNumber
Anchor link toPushNotification.prototype.getApplicationIconBadgeNumber = function( callback )[android, ios]
ส่งคืนหมายเลขแบจบนไอคอนแอปพลิเคชัน
callback – คอลแบ็กเมื่อสำเร็จ
pushwoosh.getApplicationIconBadgeNumber(function(badge){ alert(badge);} );addToApplicationIconBadgeNumber
Anchor link toPushNotification.prototype.addToApplicationIconBadgeNumber = function( badgeNumber )[android, ios]
เพิ่มค่าให้กับแบจบนไอคอนแอปพลิเคชัน
badgeNumber — หมายเลขแบจบนไอคอนที่เพิ่มขึ้น
getLaunchNotification
Anchor link toPushNotification.prototype.getLaunchNotification = function( callback )[android, ios]
ส่งคืนเพย์โหลดของการแจ้งเตือนแบบพุชหากแอปถูกเปิดขึ้นเพื่อตอบสนองต่อการแจ้งเตือนแบบพุช หรือ null
callback – คอลแบ็กเมื่อสำเร็จ
clearLaunchNotification
Anchor link toPushNotification.prototype.clearLaunchNotification = function( callback )[android, ios]
ล้างการแจ้งเตือนเมื่อเปิดแอป getLaunchNotification() จะส่งคืน null หลังจากการเรียกนี้
setUserId
Anchor link toPushNotification.prototype.setUserId = function( userId )[android, ios]
ตั้งค่าตัวระบุผู้ใช้– Facebook ID, ชื่อผู้ใช้, อีเมล, หรือ User ID อื่นๆ ซึ่งจะช่วยให้ข้อมูลและอีเวนต์สามารถจับคู่กันได้ในอุปกรณ์ต่างๆ ของผู้ใช้
userId – ตัวระบุสตริงผู้ใช้
postEvent
Anchor link toPushNotification.prototype.postEvent = function( event, attributes )[android, ios]
โพสต์อีเวนต์สำหรับข้อความในแอป ซึ่งสามารถทริกเกอร์การแสดงข้อความในแอปตามที่ระบุไว้ใน Pushwoosh Control Panel
event – อีเวนต์ที่จะทริกเกอร์
attributes – อ็อบเจกต์ที่มีแอตทริบิวต์อีเวนต์เพิ่มเติม
pushwoosh.setUserId("XXXXXX");pushwoosh.postEvent("buttonPressed", { "buttonNumber" : 4, "buttonLabel" : "banner" });createLocalNotification
Anchor link toPushNotification.prototype.createLocalNotification = function( config, success, fail )[android, ios]
กำหนดเวลาการแจ้งเตือนในเครื่อง
config.msg – ข้อความแจ้งเตือน
config.seconds – ความล่าช้าของการแจ้งเตือนเป็นวินาที
config.userData – ข้อมูลเพิ่มเติมที่จะส่งในการแจ้งเตือน
success – คอลแบ็กเมื่อสำเร็จ
fail – คอลแบ็กเมื่อเกิดข้อผิดพลาด
pushwoosh.createLocalNotification({msg:"Your pumpkins are ready!", seconds:30, userData:{}})clearLocalNotification
Anchor link toPushNotification.prototype.clearLocalNotification = function()[android]
ล้างการแจ้งเตือนในเครื่องที่รอดำเนินการทั้งหมดที่สร้างโดย createLocalNotification
clearNotificationCenter
Anchor link toPushNotification.prototype.clearNotificationCenter = function()[android]
ล้างการแจ้งเตือนทั้งหมดที่แสดงใน Android Notification Center
setMultiNotificationMode
Anchor link toPushNotification.prototype.setMultiNotificationMode = function( success, fail )[android]
อนุญาตให้แสดงการแจ้งเตือนหลายรายการใน Android Notification Center
setSingleNotificationMode
Anchor link toPushNotification.prototype.setSingleNotificationMode = function( success,fail )[android]
อนุญาตให้แสดงเฉพาะการแจ้งเตือนล่าสุดใน Android Notification Center
setSoundType
Anchor link toPushNotification.prototype.setSoundType = function( type, success, fail )[android]
ตั้งค่าเสียงเริ่มต้นสำหรับการแจ้งเตือนแบบพุชที่เข้ามา
type – ประเภทเสียง (0 – ค่าเริ่มต้น, 1 – ไม่มีเสียง, 2 – เสมอ)
setVibrateType
Anchor link toPushNotification.prototype.setVibrateType = function(type, success, fail )[android]
ตั้งค่าโหมดการสั่นเริ่มต้นสำหรับการแจ้งเตือนแบบพุชที่เข้ามา
type – ประเภทการสั่น (0 – ค่าเริ่มต้น, 1 – ไม่มีการสั่น, 2 – เสมอ)
setLightScreenOnNotification
Anchor link toPushNotification.prototype.setLightScreenOnNotification = function( on, success, fail )[android]
เปิดหน้าจอเมื่อมีการแจ้งเตือนมาถึง
on – เปิด/ปิดการปลดล็อกหน้าจอ (ปิดใช้งานโดยค่าเริ่มต้น)
setEnableLED
Anchor link toPushNotification.prototype.setEnableLED = function( on, success, fail )[android]
เปิดใช้งานไฟ LED กะพริบเมื่อมีการแจ้งเตือนมาถึงและหน้าจอดับอยู่
on – เปิด/ปิดไฟ LED กะพริบ (ปิดใช้งานโดยค่าเริ่มต้น)
setColorLED
Anchor link toPushNotification.prototype.setColorLED = function( color, success, fail )[android]
ตั้งค่าสีของไฟ LED ใช้กับ setEnableLED
color – สีของไฟ LED ในรูปแบบจำนวนเต็ม ARGB
getPushHistory
Anchor link toPushNotification.prototype.getPushHistory = function( success )[android]
ส่งคืนอาร์เรย์ของการแจ้งเตือนแบบพุชที่ได้รับ
success – คอลแบ็กเมื่อสำเร็จ
pushwoosh.getPushHistory(function(pushHistory) { if(pushHistory.length == 0) alert("no push history"); else alert(JSON.stringify(pushHistory));});
pushwoosh.clearPushHistory();clearPushHistory
Anchor link toPushNotification.prototype.clearPushHistory = function()[android]
ล้างประวัติการแจ้งเตือนแบบพุช
cancelAllLocalNotifications
Anchor link toPushNotification.prototype.cancelAllLocalNotifications = function( callback )[ios]
ล้างการแจ้งเตือนในเครื่องทั้งหมดออกจากศูนย์การแจ้งเตือน
presentInboxUI
Anchor link to[android, ios]
เปิดหน้าจอ Inbox ยอมรับอ็อบเจกต์สไตล์ที่เป็นทางเลือก ดู การตั้งค่า Message Inbox สำหรับ Cordova สำหรับรายการคีย์สไตล์ทั้งหมด
PushNotification.prototype.presentInboxUI = function( params )loadMessages
Anchor link to[android, ios]
โหลดอาร์เรย์ของข้อความในกล่องจดหมาย
PushNotification.prototype.loadMessages = function( success, fail )unreadMessagesCount
Anchor link to[android, ios]
ส่งคืนจำนวนข้อความในกล่องจดหมายที่ยังไม่ได้อ่าน
PushNotification.prototype.unreadMessagesCount = function( success )messagesCount
Anchor link to[android, ios]
ส่งคืนจำนวนข้อความทั้งหมดในกล่องจดหมาย
PushNotification.prototype.messagesCount = function( success )messagesWithNoActionPerformedCount
Anchor link to[android, ios]
ส่งคืนจำนวนข้อความในกล่องจดหมายที่ไม่มีการดำเนินการใดๆ
PushNotification.prototype.messagesWithNoActionPerformedCount = function( success )readMessage
Anchor link to[android, ios]
ทำเครื่องหมายข้อความในกล่องจดหมายว่าอ่านแล้ว
PushNotification.prototype.readMessage = function( number )deleteMessage
Anchor link to[android, ios]
ลบข้อความออกจากกล่องจดหมาย
PushNotification.prototype.deleteMessage = function( number )performAction
Anchor link to[android, ios]
ดำเนินการที่กำหนดให้กับข้อความในกล่องจดหมาย เช่น การเปิด URL
PushNotification.prototype.performAction = function( number )setCommunicationEnabled
Anchor link toเมธอดแบบไบนารีที่เปิด/ปิดการสื่อสารทั้งหมดกับ Pushwoosh ค่าบูลีน false จะยกเลิกการสมัครรับการแจ้งเตือนแบบพุชของอุปกรณ์และหยุดการดาวน์โหลดข้อความในแอป ค่า true จะให้ผลตรงกันข้าม
PushNotification.prototype.setCommunicationEnabled = function(enable, success, fail)removeAllDeviceData
Anchor link toลบข้อมูลทั้งหมดเกี่ยวกับอุปกรณ์
PushNotification.prototype.removeAllDeviceData = function()push-receive
Anchor link to[android, ios]
อีเวนต์การรับการแจ้งเตือนแบบพุช จะถูกยิงเมื่อแอปพลิเคชันได้รับการแจ้งเตือนแบบพุชในเบื้องหน้าหรือเบื้องหลัง แอปพลิเคชันที่ปิดอยู่จะไม่ได้รับอีเวนต์นี้
คุณสมบัติของอีเวนต์
message – (string) ข้อความแจ้งเตือนแบบพุช
userdata – (object/array) ข้อมูลที่กำหนดเองของการแจ้งเตือนแบบพุช
onStart – (boolean) เป็นการแจ้งเตือนเมื่อเปิดแอปหรือไม่
foreground – (boolean) ได้รับการแจ้งเตือนในเบื้องหน้าหรือไม่
android – (object) เพย์โหลดการแจ้งเตือนเฉพาะของ Android
ios – (object) เพย์โหลดการแจ้งเตือนเฉพาะของ iOS
windows – (object) เพย์โหลดการแจ้งเตือนเฉพาะของ Windows
document.addEventListener('push-receive', function(event) { var userData = event.notification.userdata;
if (typeof(userData) != "undefined") { // handle custom notification data console.warn('user data: ' + JSON.stringify(userData)); } });การแจ้งเตือนในเบื้องหน้า
Anchor link toโดยค่าเริ่มต้น ปลั๊กอิน Pushwoosh จะไม่แสดงการแจ้งเตือนในเบื้องหน้าและจะทริกเกอร์อีเวนต์ push-receive โดยอัตโนมัติ ดู คู่มือการปรับแต่งปลั๊กอิน สำหรับการควบคุมพฤติกรรมนี้
push-notification
Anchor link to[android, ios, wp8, windows]
อีเวนต์การยอมรับการแจ้งเตือนแบบพุช จะถูกยิงเมื่อผู้ใช้แตะที่การแจ้งเตือนแบบพุช
document.addEventListener('push-notification', function(event) { var message = event.notification.message; var userData = event.notification.userdata;
if (typeof(userData) != "undefined") { console.warn('user data: ' + JSON.stringify(userData)); } });คุณสมบัติของอีเวนต์
เหมือนกับ push-receive
additionalAuthorizationOptions
Anchor link to[ios only]
ให้ตัวเลือกการอนุญาตการแจ้งเตือน_เ_พิ่มเติม notification authorization options ควรเรียกใช้ก่อนที่จะเรียก registerDevice
pushwoosh.additionalAuthorizationOptions({ "UNAuthorizationOptionCriticalAlert" : 1, "UNAuthorizationOptionProvisional": 0 // set 0 or don't specify the option if you don't want to add it to your app.});