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

مرجع واجهة برمجة التطبيقات (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 – دالة رد النداء (callback) للنجاح. يتم تمرير رمز الإشعار كمعامل “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('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]
يعيد معرف الجهاز (HWID) الخاص بـ Pushwoosh المستخدم للتواصل مع واجهة برمجة تطبيقات Pushwoosh.

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" : تم منح إذن الشارات. (iOS فقط)
"pushAlert" : تم منح إذن التنبيهات. (iOS فقط)
"pushSound" : تم منح إذن الصوت. (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]
ينشر الأحداث للرسائل داخل التطبيق (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("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]
يفتح شاشة صندوق الوارد.

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('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 فقط]
يوفر خيارات تفويض إضافية للإشعارات. يجب استدعاؤه قبل استدعاء registerDevice.

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