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

مرجع واجهة برمجة التطبيقات (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",
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.serviceName – اسم خدمة MPNS لمنصة wp8.

مثال
// تهيئة Pushwoosh باستخدام appid: "PUSHWOOSH_APP_ID"، serviceName: "WINDOWS_PHONE_SERVICE". سيؤدي هذا إلى إطلاق جميع الإشعارات الفورية المعلقة عند البدء.
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]
يضبط الوسوم للجهاز.

المعاملات

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]
يعيد 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" : تم منح إذن الشارات. (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 indentifier) – معرف فيسبوك، اسم مستخدم، بريد إلكتروني، أو أي معرف مستخدم آخر. يسمح هذا بمطابقة البيانات والأحداث عبر أجهزة المستخدم المتعددة.

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

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