دليل التكامل الأساسي لـ Unity SDK
يرشدك هذا الدليل خلال عملية دمج Pushwoosh Unity SDK في تطبيقك.
المتطلبات الأساسية
Anchor link toخطوات التكامل
Anchor link to1. إضافة Pushwoosh Unity SDK
Anchor link toأضف ما يلي إلى ملف Packages/manifest.json الخاص بك:
{ "dependencies": { "com.pushwoosh.unity.core": "6.2.7", "com.pushwoosh.unity.android": "6.2.7", "com.pushwoosh.unity.ios": "6.2.7" }, "scopedRegistries": [ { "name": "npmjs", "url": "https://registry.npmjs.org", "scopes": ["com.pushwoosh"] } ]}أضف فقط حزم المنصة التي تحتاجها. على سبيل المثال، احذف com.pushwoosh.unity.android إذا كنت تستهدف iOS فقط.
في Unity، انتقل إلى Window > Package Manager > + > Add package from git URL وأضف عناوين URL التالية واحدًا تلو الآخر:
https://github.com/Pushwoosh/pushwoosh-unity.git?path=com.pushwoosh.unity.corehttps://github.com/Pushwoosh/pushwoosh-unity.git?path=com.pushwoosh.unity.androidhttps://github.com/Pushwoosh/pushwoosh-unity.git?path=com.pushwoosh.unity.iosقم بتنزيل Pushwoosh.unitypackage من إصدارات GitHub وقم باستيراده عبر Assets > Import Package > Custom Package.
2. تثبيت External Dependency Manager
Anchor link toيتطلب SDK External Dependency Manager for Unity (EDM4U) لحل الاعتماديات الأصلية لـ Android و iOS.
أضف scoped registry التالي إلى ملف Packages/manifest.json الخاص بك:
{ "scopedRegistries": [ { "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": ["com.google.external-dependency-manager"] } ]}ثم أضف الحزمة إلى اعتمادياتك:
"com.google.external-dependency-manager": "1.2.183"3. تهيئة SDK
Anchor link toأنشئ سكربت PushNotificator.cs وأرفقه بأي GameObject في المشهد:
using UnityEngine;using System.Collections.Generic;
public class PushNotificator : MonoBehaviour{ void Start() { Pushwoosh.ApplicationCode = "XXXXX-XXXXX"; Pushwoosh.FcmProjectNumber = "XXXXXXXXXXXX";
Pushwoosh.Instance.OnRegisteredForPushNotifications += (token) => { Debug.Log("Push token: " + token); };
Pushwoosh.Instance.OnFailedToRegisteredForPushNotifications += (error) => { Debug.Log("Registration failed: " + error); };
Pushwoosh.Instance.RegisterForPushNotifications(); }}استبدل:
XXXXX-XXXXXبرمز تطبيق Pushwoosh الخاص بك.XXXXXXXXXXXXبرقم مشروع Firebase الخاص بك (لـ Android فقط).
4. الإعداد الأصلي لـ iOS
Anchor link to4.1 القدرات (Capabilities)
Anchor link toبعد بناء مشروع iOS من Unity، افتح مشروع Xcode الذي تم إنشاؤه وأضف القدرات التالية في Signing & Capabilities:
- Push Notifications
- Background Modes مع تحديد Remote notifications
بالنسبة للإشعارات الحساسة للوقت (Time Sensitive Notifications) (iOS 15+)، أضف أيضًا قدرة Time Sensitive Notifications.
4.2 Info.plist
Anchor link toأضف Pushwoosh Device API Token إلى ملف Info.plist الخاص بك:
<key>Pushwoosh_API_TOKEN</key><string>__PUSHWOOSH_DEVICE_API_TOKEN__</string>4.3 تتبع تسليم الرسائل
Anchor link toأضف هدف Notification Service Extension إلى مشروع Xcode الخاص بك. هذا مطلوب لتتبع التسليم الدقيق والوسائط الغنية (Rich Media) على iOS.
اتبع الدليل الأصلي لإضافة هدف الامتداد.
5. الإعداد الأصلي لـ Android
Anchor link to5.1 إضافة ملف تكوين Firebase
Anchor link toضع ملف google-services.json في دليل Assets بمشروع Unity الخاص بك.
5.2 إضافة بيانات Pushwoosh الوصفية
Anchor link toأضف Pushwoosh Device API Token إلى ملف Assets/Plugins/Android/AndroidManifest.xml الخاص بك داخل وسم <application>:
<meta-data android:name="com.pushwoosh.apitoken" android:value="__YOUR_DEVICE_API_TOKEN__" />6. تشغيل المشروع
Anchor link to- قم ببناء وتشغيل المشروع على المنصة المستهدفة.
- امنح الإذن للإشعارات الفورية عند الطلب.
- اذهب إلى لوحة تحكم Pushwoosh و أرسل إشعارًا فوريًا.
التكامل الممتد
Anchor link toفي هذه المرحلة، يمكنك إرسال واستقبال الإشعارات الفورية. تغطي الأقسام أدناه الوظائف الأساسية لـ SDK.
مستمعو أحداث الإشعارات الفورية
Anchor link toيوفر SDK مستمعي أحداث للتعامل مع الإشعارات الفورية:
OnPushNotificationsReceived— يتم تشغيله عند وصول إشعار فوريOnPushNotificationsOpened— يتم تشغيله عندما ينقر المستخدم على إشعار
قم بإعداد هؤلاء المستمعين أثناء تهيئة SDK:
void Start(){ Pushwoosh.ApplicationCode = "XXXXX-XXXXX"; Pushwoosh.FcmProjectNumber = "XXXXXXXXXXXX";
Pushwoosh.Instance.OnPushNotificationsReceived += (payload) => { Debug.Log("Push received: " + payload); };
Pushwoosh.Instance.OnPushNotificationsOpened += (payload) => { Debug.Log("Push opened: " + payload); };
Pushwoosh.Instance.RegisterForPushNotifications();}تكوين المستخدم
Anchor link toقم بتخصيص الإشعارات الفورية عن طريق تحديد المستخدمين وتعيين خصائصهم:
// تعيين معرّف المستخدم للتتبع عبر الأجهزةPushwoosh.Instance.SetUserId("user-123");
// تعيين بريد المستخدم الإلكترونيPushwoosh.Instance.SetEmail("user@example.com");
// تعيين المستخدم بالمعرّف والبريد الإلكتروني معًاPushwoosh.Instance.SetUser("user-123", new List<string> { "user@example.com" });
// تعيين اللغة المفضلةPushwoosh.Instance.SetLanguage("en");العلامات (Tags)
Anchor link toالعلامات (Tags) هي أزواج من المفاتيح والقيم يتم تعيينها للأجهزة، مما يتيح تجزئة المستخدمين والمراسلة المستهدفة:
// علامة نصيةPushwoosh.Instance.SetStringTag("favorite_category", "electronics");
// علامة عدد صحيحPushwoosh.Instance.SetIntTag("purchase_count", 5);
// علامة قائمةPushwoosh.Instance.SetListTag("interests", new List<object> { "sports", "music", "tech" });
// الحصول على جميع العلاماتPushwoosh.Instance.GetTags((tags, error) => { if (error != null) { Debug.Log("Error: " + error.Message); return; } foreach (var tag in tags) { Debug.Log(tag.Key + ": " + tag.Value); }});الأحداث (Events)
Anchor link toتتبع إجراءات المستخدم لتحليل السلوك وتشغيل الرسائل الآلية:
// تتبع حدث تسجيل الدخولPushwoosh.Instance.PostEvent("login", new Dictionary<string, object> { { "username", "user-123" }, { "login_type", "email" }});
// تتبع حدث شراءPushwoosh.Instance.PostEvent("purchase", new Dictionary<string, object> { { "product_id", "SKU-001" }, { "price", 29.99 }, { "currency", "USD" }});تفضيلات الاتصال
Anchor link toاسمح للمستخدمين بالاشتراك في الإشعارات الفورية أو إلغاء الاشتراك فيها برمجيًا:
// تمكين الاتصالPushwoosh.Instance.SetCommunicationEnabled(true);
// تعطيل الاتصالPushwoosh.Instance.SetCommunicationEnabled(false);
// التحقق من الحالة الحاليةbool isEnabled = Pushwoosh.Instance.IsCommunicationEnabled();إدارة الشارة (Badge)
Anchor link toتحكم في رقم شارة التطبيق على المنصات المدعومة:
// تعيين الشارة إلى رقم محددPushwoosh.Instance.SetBadgeNumber(3);
// زيادة الشارةPushwoosh.Instance.AddBadgeNumber(1);
// مسح الشارةPushwoosh.Instance.SetBadgeNumber(0);استكشاف الأخطاء وإصلاحها
Anchor link toإذا واجهت أي مشاكل أثناء عملية التكامل، فارجع إلى قسم الدعم والمجتمع.