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

إشعار الدفع المخصص في المقدمة لنظام iOS

بدءًا من الإصدار 6.10.0، يمكنك دمج وحدة PushwooshForegroundPush لتخصيص إشعارات الدفع في المقدمة عند تعطيل تنبيهات نظام iOS الأصلية.

1. تعطيل تنبيهات الدفع الأصلية في المقدمة

Anchor link to

أضف Pushwoosh_SHOW_ALERT = false إلى ملف Info.plist الخاص بك.

<key>Pushwoosh_SHOW_ALERT</key>
<false/>

2. دمج وحدة PushwooshForegroundPush

Anchor link to

Swift Package Manager

Cocoapods

Terminal window
# Uncomment the next line to define a global platform for your project
# platform :ios, '13.0'
target 'MyApp' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
pod 'PushwooshXCFramework'
pod 'PushwooshFramework/PushwooshForegroundPush'
end

3. إضافة تكوين PushwooshForegroundPush في AppDelegate

Anchor link to
import UIKit
import PushwooshFramework
import PushwooshForegroundPush
@main
class AppDelegate: UIResponder, UIApplicationDelegate, PWMessagingDelegate, PWForegroundPushDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Pushwoosh.ForegroundPush.foregroundNotificationWith(style: .style1,
duration: 5,
vibration: .notification,
disappearedPushAnimation: .balls)
Pushwoosh.ForegroundPush.delegate = self
return true
}
func pushwoosh(_ pushwoosh: Pushwoosh, onMessageReceived message: PWMessage) {
if let payload = message.payload {
// Pushwoosh method
Pushwoosh.ForegroundPush.showForegroundPush(userInfo: payload)
}
}
}

استخدام دالة foregroundNotificationWith

تسمح لك دالة foregroundNotificationWith بعرض إشعار دفع مخصص في المقدمة بنمط ومدة وردود فعل لمسية قابلة للتكوين.

توقيع الدالة (Swift / Objective-C):

@objc
static func foregroundNotificationWith(
style: PWForegroundPushStyle,
duration: Int,
vibration: PWForegroundPushHapticFeedback,
disappearedPushAnimation: PWForegroundPushDisappearedAnimation
)

المعلمات:

  1. style (PWForegroundPushStyle)
  • حاليًا، يتوفر style1 فقط.
  1. duration (Int)
  • تحدد مدة عرض الإشعار قبل اختفائه (بالثواني).
  1. vibration (PWForegroundPushHapticFeedback)
  • تتحكم في ردود الفعل اللمسية عند عرض الإشعار. الخيارات المتاحة:
case none // لا يوجد اهتزاز
case light // اهتزاز خفيف
case medium // اهتزاز متوسط
case heavy // اهتزاز قوي
case soft // اهتزاز ناعم
case rigid // اهتزاز صلب
case notification // اهتزاز الإشعار القياسي
  1. disappearedPushAnimation (PWForegroundPushDisappearedAnimation)
  • الرسوم المتحركة لاختفاء الإشعار
case balls = 0
case regularPush

4. تنفيذ دالة المفوّض didTapForegroundPush

Anchor link to

لمعالجة نقرات المستخدم على إشعارات الدفع المخصصة في المقدمة، قم بتنفيذ دالة بروتوكول PWForegroundPushDelegate:

// معالجة النقر على إشعار الدفع في المقدمة
func didTapForegroundPush(_ userInfo: [AnyHashable : Any]) {
print("Foreground custom push: \(userInfo)")
// قم بأي إجراء، على سبيل المثال، الانتقال إلى شاشة معينة
// navigateToScreen(for: userInfo)
}

ملاحظات:

  • تُستدعى هذه الدالة عندما ينقر المستخدم على إشعار دفع مخصص في المقدمة.
  • يحتوي userInfo على حمولة (payload) الإشعار.
  • تأكد من تعيين Pushwoosh.ForegroundPush.delegate = self بعد التكوين.

5. معلمات اختيارية لتخصيص إشعارات الدفع في المقدمة

Anchor link to

توفر وحدة PushwooshForegroundPush العديد من المعلمات الاختيارية لتخصيص مظهر وسلوك إشعارات الدفع في المقدمة. يمكن تعيينها بشكل عام عبر الخصائص الثابتة (static properties).

الخاصيةالنوعالوصفالافتراضي
useLiquidViewBoolاستخدام عرض Liquid Glass على نظام iOS 26.false
gradientColors[UIColor]?مصفوفة اختيارية من الألوان لخلفية متدرجة.nil
backgroundColorUIColor?لون خلفية الإشعار. إذا كانت nil ولم يتم تعيين gradientColors، فسيتم استخدام التدرج الافتراضي.تدرج النظام الافتراضي
usePushAnimationBoolما إذا كان سيتم تحريك الإشعار عند عرضه.true
titlePushColorUIColor?لون نص عنوان الإشعار. الافتراضي هو اللون الأبيض للنظام إذا كانت nil.white
messagePushColorUIColor?لون نص رسالة الإشعار. الافتراضي هو اللون الأبيض للنظام إذا كانت nil.white
titlePushFontUIFont?خط نص عنوان الإشعار. الافتراضي هو خط النظام إذا كانت nil.خط النظام الافتراضي
messagePushFontUIFont?خط نص رسالة الإشعار. الافتراضي هو خط النظام إذا كانت nil.خط النظام الافتراضي

ملخص:

  • Swift 5.13+ + iOS 26 ← Liquid Glass
  • Swift 5.13+ + iOS < 26 ← UIView قياسي
  • Swift < 5.13 ← عرض ضبابي دائمًا (لا يوجد دعم لـ Liquid Glass)

مثال على الاستخدام:

Pushwoosh.ForegroundPush.useLiquidView = true
Pushwoosh.ForegroundPush.gradientColors = [.red, .orange, .yellow]
Pushwoosh.ForegroundPush.titlePushColor = .red
Pushwoosh.ForegroundPush.messagePushColor = .green
Pushwoosh.ForegroundPush.backgroundColor = .black
Pushwoosh.ForegroundPush.titlePushFont = .boldSystemFont(ofSize: 22)
Pushwoosh.ForegroundPush.messagePushFont = .italicSystemFont(ofSize: 15)
Pushwoosh.ForegroundPush.usePushAnimation = false

6. مثال على إشعار الدفع في المقدمة

Anchor link to

يوضح هذا المثال كيفية عرض إشعار دفع مخصص في المقدمة مع title و message و cards ورسوم متحركة GIF.

إشعار دفع Pushwoosh في المقدمة مع عرض Liquid Glass متحرك
إشعار دفع Pushwoosh في المقدمة مع مرفق gif
إشعار دفع Pushwoosh في المقدمة مع صورة بطاقة
إشعار دفع Pushwoosh في المقدمة مع تدرج مخصص، وألوان مخصصة للعنوان والرسالة
إشعار دفع Pushwoosh في المقدمة مع خلفية مخصصة، وخطوط مخصصة للعنوان والرسالة، وبدون رسوم متحركة

هذا كل شيء. لقد قمت بتكوين إشعارات الدفع المخصصة في المقدمة بنجاح في نظام iOS باستخدام Pushwoosh.