انتقل إلى المحتوى

مرجع واجهة برمجة تطبيقات إضافة Cordova

مثال
var pushwoosh = cordova.require("pushwoosh-cordova-plugin.PushNotification");
// Should be called before pushwoosh.onDeviceReady
document.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 to
PushNotification.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 to
PushNotification.prototype.registerDevice = function( success, fail )

[android, ios, wp8, windows] يسجل الجهاز لتلقي الإشعارات الفورية ويسترجع رمز الدفع (push Token).

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 to
PushNotification.prototype.unregisterDevice = function( success, fail )

[android, ios, wp8, windows] يلغي تسجيل الجهاز من تلقي الإشعارات الفورية.

success – رد نداء النجاح.

fail – رد نداء الخطأ.

PushNotification.prototype.setTags = function( config, success, fail )

[android, ios, wp8, windows] يضبط العلامات (Tags) للجهاز.

المعاملات

config – كائن يحتوي على علامات الجهاز المخصصة.

success – رد نداء النجاح. يتم تمرير رمز الدفع كمعامل “status.pushToken” إلى رد النداء هذا.

fail – رد نداء الخطأ.

مثال
// sets tags: “deviceName” with value “hello” and “deviceId” with value 10
pushwoosh.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"]});
PushNotification.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 to
PushNotification.prototype.getPushToken = function( success )

[android, ios, wp8, windows] يعيد رمز الدفع إذا كان متاحًا. لاحظ أن الرمز يأتي أيضًا في رد نداء دالة registerDevice.

success – رد نداء النجاح.

pushwoosh.getPushToken(
function(token) {
console.warn('push token: ' + token);
}
);

getPushwooshHWID

Anchor link to
PushNotification.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 to
PushNotification.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 to
PushNotification.prototype.setApplicationIconBadgeNumber = function( badgeNumber )

[android, ios] يضبط رقم شارة أيقونة التطبيق.

badgeNumber – رقم شارة الأيقونة.

getApplicationIconBadgeNumber

Anchor link to
PushNotification.prototype.getApplicationIconBadgeNumber = function( callback )

[android, ios] يعيد رقم شارة أيقونة التطبيق.

callback – رد نداء النجاح.

pushwoosh.getApplicationIconBadgeNumber(function(badge){ alert(badge);} );

addToApplicationIconBadgeNumber

Anchor link to
PushNotification.prototype.addToApplicationIconBadgeNumber = function( badgeNumber )

[android, ios] يضيف قيمة إلى شارة أيقونة التطبيق.

badgeNumber — رقم شارة الأيقونة التزايدي.

getLaunchNotification

Anchor link to
PushNotification.prototype.getLaunchNotification = function( callback )

[android, ios] يعيد حمولة الإشعار الفوري إذا تم بدء التطبيق استجابةً لإشعار فوري، أو null.

callback – رد نداء النجاح.

clearLaunchNotification

Anchor link to
PushNotification.prototype.clearLaunchNotification = function( callback )

[android, ios] يمسح إشعار التشغيل، ستعيد getLaunchNotification() القيمة null بعد هذا الاستدعاء.

PushNotification.prototype.setUserId = function( userId )

[android, ios] يضبط معرف المستخدم (User ID) – معرف فيسبوك، اسم مستخدم، بريد إلكتروني، أو أي معرف مستخدم آخر. يسمح هذا بمطابقة البيانات والأحداث عبر أجهزة المستخدم المتعددة.

userId – معرف المستخدم النصي.

PushNotification.prototype.postEvent = function( event, attributes )

[android, ios] ينشر أحداثًا لرسائل In-App. يمكن أن يؤدي هذا إلى عرض رسالة In-App كما هو محدد في لوحة تحكم Pushwoosh.

event – الحدث الذي سيتم إطلاقه.

attributes – كائن بسمات حدث إضافية.

pushwoosh.setUserId("XXXXXX");
pushwoosh.postEvent("buttonPressed", { "buttonNumber" : 4, "buttonLabel" : "banner" });

createLocalNotification

Anchor link to
PushNotification.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 to
PushNotification.prototype.clearLocalNotification = function()

[android] يمسح جميع الإشعارات المحلية المعلقة التي تم إنشاؤها بواسطة createLocalNotification.

clearNotificationCenter

Anchor link to
PushNotification.prototype.clearNotificationCenter = function()

[android] يمسح جميع الإشعارات المعروضة في مركز إشعارات Android.

setMultiNotificationMode

Anchor link to
PushNotification.prototype.setMultiNotificationMode = function( success, fail )

[android] يسمح بعرض إشعارات متعددة في مركز إشعارات Android.

setSingleNotificationMode

Anchor link to
PushNotification.prototype.setSingleNotificationMode = function( success,
fail )

[android] يسمح بعرض الإشعار الأخير فقط في مركز إشعارات Android.

setSoundType

Anchor link to
PushNotification.prototype.setSoundType = function( type, success, fail )

[android] يضبط الصوت الافتراضي للإشعارات الفورية الواردة.

type – نوع الصوت (0 – افتراضي، 1 – بدون صوت، 2 – دائمًا).

setVibrateType

Anchor link to
PushNotification.prototype.setVibrateType = function(type, success, fail )

[android] يضبط وضع الاهتزاز الافتراضي للإشعارات الفورية الواردة.

type – نوع الاهتزاز (0 – افتراضي، 1 – بدون اهتزاز، 2 – دائمًا).

setLightScreenOnNotification

Anchor link to
PushNotification.prototype.setLightScreenOnNotification = function( on, success, fail )

[android] يشغل الشاشة عند وصول الإشعار.

on – تمكين/تعطيل فتح الشاشة (معطل افتراضيًا).

setEnableLED

Anchor link to
PushNotification.prototype.setEnableLED = function( on, success, fail )

[android] يمكّن وميض LED عند وصول الإشعار وإيقاف تشغيل الشاشة.

on – تمكين/تعطيل وميض LED (معطل افتراضيًا).

setColorLED

Anchor link to
PushNotification.prototype.setColorLED = function( color, success, fail )

[android] يضبط لون LED. استخدم مع setEnableLED.

color – لون LED بتنسيق عدد صحيح ARGB.

getPushHistory

Anchor link to
PushNotification.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 to
PushNotification.prototype.clearPushHistory = function()

[android] يمسح سجل الإشعارات الفورية.

cancelAllLocalNotifications

Anchor link to
PushNotification.prototype.cancelAllLocalNotifications = function( callback )

[ios] يمسح جميع الإشعارات المحلية من مركز الإشعارات.

presentInboxUI

Anchor link to

[android, ios] يفتح شاشة 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] يوفر خيارات تفويض إضافية للإشعارات. يجب استدعاؤه قبل استدعاء 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.
});