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

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

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

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

```xml
<key>Pushwoosh_SHOW_ALERT</key>
<false/>
```

### 2. دمج وحدة `PushwooshForegroundPush`

**Swift Package Manager**
<img src="/spm-foreground-push-ios.webp" alt=""/>

<Aside type="caution" title="هام">
الوحدات ```PushwooshFramework``` و ```PushwooshCore``` و ```PushwooshBridge``` و ```PushwooshLiveActivities``` **مطلوبة**.
</Aside>

**Cocoapods**
```bash
# 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

```swift
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):

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

`المعلمات:`

1. `style` (`PWForegroundPushStyle`)
* حاليًا، يتوفر `style1` فقط.

2. `duration` (`Int`)
* تحدد مدة عرض الإشعار قبل اختفائه (بالثواني).

3. `vibration` (`PWForegroundPushHapticFeedback`)
* تتحكم في ردود الفعل اللمسية عند عرض الإشعار. الخيارات المتاحة:

```swift
case none           // لا يوجد اهتزاز
case light          // اهتزاز خفيف
case medium         // اهتزاز متوسط
case heavy          // اهتزاز قوي
case soft           // اهتزاز ناعم
case rigid          // اهتزاز صلب
case notification   // اهتزاز الإشعار القياسي
```

4. `disappearedPushAnimation` (`PWForegroundPushDisappearedAnimation`)
* الرسوم المتحركة لاختفاء الإشعار

```swift
case balls = 0
case regularPush
```

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

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

```swift
// معالجة النقر على إشعار الدفع في المقدمة
func didTapForegroundPush(_ userInfo: [AnyHashable : Any]) {
    print("Foreground custom push: \(userInfo)")

    // قم بأي إجراء، على سبيل المثال، الانتقال إلى شاشة معينة
    // navigateToScreen(for: userInfo)
}
```

ملاحظات:

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

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

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

<table>
  <thead>
    <tr>
      <th style={{ width: '20%' }}>الخاصية</th>
      <th style={{ width: '15%' }}>النوع</th>
      <th style={{ width: '45%' }}>الوصف</th>
      <th style={{ width: '20%' }}>الافتراضي</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>useLiquidView</td>
      <td>Bool</td>
      <td>استخدام عرض Liquid Glass على نظام iOS 26.</td>
      <td>false</td>
    </tr>
    <tr>
      <td>gradientColors</td>
      <td>[UIColor]?</td>
      <td>مصفوفة اختيارية من الألوان لخلفية متدرجة.</td>
      <td>nil</td>
    </tr>
    <tr>
      <td>backgroundColor</td>
      <td>UIColor?</td>
      <td>لون خلفية الإشعار. إذا كانت `nil` ولم يتم تعيين `gradientColors`، فسيتم استخدام التدرج الافتراضي.</td>
      <td>تدرج النظام الافتراضي</td>
    </tr>
    <tr>
      <td>usePushAnimation</td>
      <td>Bool</td>
      <td>ما إذا كان سيتم تحريك الإشعار عند عرضه.</td>
      <td>true</td>
    </tr>
    <tr>
      <td>titlePushColor</td>
      <td>UIColor?</td>
      <td>لون نص عنوان الإشعار. الافتراضي هو اللون الأبيض للنظام إذا كانت `nil`.</td>
      <td>white</td>
    </tr>
    <tr>
      <td>messagePushColor</td>
      <td>UIColor?</td>
      <td>لون نص رسالة الإشعار. الافتراضي هو اللون الأبيض للنظام إذا كانت `nil`.</td>
      <td>white</td>
    </tr>
    <tr>
      <td>titlePushFont</td>
      <td>UIFont?</td>
      <td>خط نص عنوان الإشعار. الافتراضي هو خط النظام إذا كانت `nil`.</td>
      <td>خط النظام الافتراضي</td>
    </tr>
    <tr>
      <td>messagePushFont</td>
      <td>UIFont?</td>
      <td>خط نص رسالة الإشعار. الافتراضي هو خط النظام إذا كانت `nil`.</td>
      <td>خط النظام الافتراضي</td>
    </tr>
  </tbody>
</table>

<Aside type="caution" title="هام">
- إذا تم تمكين علامة `useLiquidView` ولكن إصدار نظام المستخدم أقل من **iOS 26**، فسيتم عرض إشعار دفع عادي يعتمد على `UIView` بدلاً من ذلك.
- إذا تم تجميع مشروعك بإصدار Swift **أقل من 5.13**، فلن يكون تأثير Liquid Glass متاحًا على الإطلاق — حتى على نظام iOS 26. في هذه الحالة، سيتم استخدام `UIVisualEffectView` ضبابي (مع `UIBlurEffect`) بدلاً من ذلك على جميع الأجهزة.
</Aside>

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


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

```swift
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. مثال على إشعار الدفع في المقدمة

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

<figure style={{ textAlign: "center" }}>
  <video src="/ios-foreground-custom-5.webm" title="مثال" autoplay loop muted playsinline />
  <figcaption>إشعار دفع Pushwoosh في المقدمة مع عرض Liquid Glass متحرك</figcaption>
</figure>

<figure style={{ textAlign: "center" }}>
  <video src="/ios-foreground-custom-1.webm" title="مثال" autoplay loop muted playsinline />
  <figcaption>إشعار دفع Pushwoosh في المقدمة مع مرفق gif</figcaption>
</figure>

<figure style={{ textAlign: "center" }}>
  <video src="/ios-foreground-custom-2.webm" title="مثال" autoplay loop muted playsinline />
  <figcaption>إشعار دفع Pushwoosh في المقدمة مع صورة بطاقة</figcaption>
</figure>

<figure style={{ textAlign: "center" }}>
  <video src="/ios-foreground-custom-3.webm" title="مثال" autoplay loop muted playsinline />
  <figcaption>إشعار دفع Pushwoosh في المقدمة مع تدرج مخصص، وألوان مخصصة للعنوان والرسالة</figcaption>
</figure>

<figure style={{ textAlign: "center" }}>
  <video src="/ios-foreground-custom-4.webm" title="مثال" autoplay loop muted playsinline />
  <figcaption>إشعار دفع Pushwoosh في المقدمة مع خلفية مخصصة، وخطوط مخصصة للعنوان والرسالة، وبدون رسوم متحركة</figcaption>
</figure>

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