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

مرجع واجهة برمجة التطبيقات (API) لمكوّن Cordova الإضافي

مثال
var pushwoosh = cordova.require("pushwoosh-cordova-plugin.PushNotification");
// يجب استدعاؤها قبل pushwoosh.onDeviceReady
document.addEventListener('push-notification', function(event) {
var notification = event.notification;
// تعامل مع فتح الإشعار هنا
});
// تهيئة Pushwoosh. سيؤدي هذا إلى تشغيل جميع الإشعارات الفورية المعلقة عند البدء.
pushwoosh.onDeviceReady({
appid: "XXXXX-XXXXX",
projectid: "XXXXXXXXXXXXXXX",
serviceName: "XXXX"
});
pushwoosh.registerDevice(
function(status) {
var pushToken = status.pushToken;
// تعامل مع التسجيل الناجح هنا
},
function(status) {
// تعامل مع خطأ التسجيل هنا
}
);

onDeviceReady

Anchor link to
PushNotification.prototype.onDeviceReady = function( config )

[android, ios, wp8, windows]
يقوم بتهيئة مكوّن Pushwoosh الإضافي ويطلق رسالة إشعار بدء. يجب استدعاؤه عند كل تشغيل للتطبيق.

config.appid – رمز تطبيق Pushwoosh.

config.projectid – رقم مشروع GCM لمنصة Android.

config.serviceName – اسم خدمة MPNS لمنصة wp8.

مثال
// تهيئة Pushwoosh باستخدام projectid: "GOOGLE_PROJECT_NUMBER", appid : "PUSHWOOSH_APP_ID", serviceName : "WINDOWS_PHONE_SERVICE". سيؤدي هذا إلى تشغيل جميع الإشعارات الفورية المعلقة عند البدء.
pushwoosh.onDeviceReady({
appid : "XXXXX-XXXXX",
projectid: "XXXXXXXXXXXXXXX",
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("تم التسجيل برمز الإشعار: " + status.pushToken);
},
function(error) {
alert("فشل التسجيل: " + 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 – دالة رد نداء الخطأ.

مثال
// يضبط العلامات: “deviceName” بالقيمة “hello” و “deviceId” بالقيمة 10
pushwoosh.setTags({deviceName:"hello", deviceId:10},
function() {
console.warn('setTags success');
},
function(error) {
console.warn('setTags failed');
}
);
// يضبط علامات القائمة "MyTag" بالقيم (مصفوفة) "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('علامات الجهاز: ' + JSON.stringify(tags));
},
function(error) {
console.warn('خطأ في الحصول على العلامات: ' + JSON.stringify(error));
}
);

getPushToken

Anchor link to
PushNotification.prototype.getPushToken = function( success )

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

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

pushwoosh.getPushToken(
function(token) {
console.warn('رمز الإشعار: ' + 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" : علامة تمكين الإشعارات.
"pushBadge" : تم منح إذن الشارات (badges). (iOS فقط)
"pushAlert" : تم منح إذن التنبيهات (alert). (iOS فقط)
"pushSound" : تم منح إذن الصوت (sound). (iOS فقط)
}

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]
ينشر الأحداث (Events) للرسائل داخل التطبيق (In-App Messages). يمكن أن يؤدي هذا إلى عرض رسالة داخل التطبيق كما هو محدد في لوحة تحكم 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("لا يوجد سجل إشعارات");
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).

PushNotification.prototype.presentInboxUI = function()

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") {
// تعامل مع بيانات الإشعار المخصصة
console.warn('بيانات المستخدم: ' + 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('بيانات المستخدم: ' + JSON.stringify(userData));
}
}
);

خصائص الحدث

نفس خصائص push-receive

additionalAuthorizationOptions

Anchor link to

[ios فقط]
يوفر خيارات تفويض إضافية للإشعارات. يجب استدعاؤها قبل استدعاء registerDevice.

pushwoosh.additionalAuthorizationOptions({
"UNAuthorizationOptionCriticalAlert" : 1,
"UNAuthorizationOptionProvisional": 0 // اضبط القيمة على 0 أو لا تحدد الخيار إذا كنت لا تريد إضافته إلى تطبيقك.
});