# iOS custom foreground push notification

Starting from version 6.10.0, you can integrate the `PushwooshForegroundPush` module to customize foreground push notifications when native iOS system alerts are disabled.

### 1. Disable native foreground push alerts 

Adding `Pushwoosh_SHOW_ALERT = false` to your `Info.plist`.

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

### 2. Integrating the `PushwooshForegroundPush` Module

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

<Aside type="caution" title="Important">
The modules ```PushwooshFramework```, ```PushwooshCore```, ```PushwooshBridge```, and ```PushwooshLiveActivities``` are **required**.
</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. Add `PushwooshForegroundPush` Configuration in 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)
        }
    }
}
```

Using `foregroundNotificationWith` Method

The foregroundNotificationWith method allows you to display a custom foreground push notification with configurable style, duration, and haptic feedback.

Method Signature (Swift / Objective-C):

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

`Parameters:`

1. `style` (`PWForegroundPushStyle`)
* Currently, only style1 is available.

2. `duration` (`Int`)
* Specifies how long the notification will be displayed before disappearing (in seconds).

3. `vibration` (`PWForegroundPushHapticFeedback`)
* Controls the haptic feedback when the notification is shown. Available options:

```swift
case none           // No vibration
case light          // Light vibration
case medium         // Medium vibration
case heavy          // Heavy vibration
case soft           // Soft vibration
case rigid          // Rigid vibration
case notification   // Standard notification vibration
```

4. `disappearedPushAnimation` (`PWForegroundPushDisappearedAnimation`)
* Push disappearance animation

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

### 4. Implementing `didTapForegroundPush` Delegate Method

To handle user taps on custom foreground push notifications, implement the `PWForegroundPushDelegate` protocol method:

```swift
// Handle tap on foreground push
func didTapForegroundPush(_ userInfo: [AnyHashable : Any]) {
    print("Foreground custom push: \(userInfo)")

    // Perform any action, e.g., navigate to a specific screen
    // navigateToScreen(for: userInfo)
}
```

Notes:

* This method is called when the user taps on a custom foreground push.
* userInfo contains the payload of the notification.
* Make sure to set `Pushwoosh.ForegroundPush.delegate = self` after configuration.

### 5. Optional Parameters for Customizing Foreground Push Notifications

The `PushwooshForegroundPush` module provides several optional parameters to customize the appearance and behavior of your foreground push notifications. These can be set globally via static properties.

<table>
  <thead>
    <tr>
      <th style={{ width: '20%' }}>Property</th>
      <th style={{ width: '15%' }}>Type</th>
      <th style={{ width: '45%' }}>Description</th>
      <th style={{ width: '20%' }}>Default</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>useLiquidView</td>
      <td>Bool</td>
      <td>Use Liquid Glass view on iOS 26.</td>
      <td>false</td>
    </tr>
    <tr>
      <td>gradientColors</td>
      <td>[UIColor]?</td>
      <td>Optional array of colors for a gradient background.</td>
      <td>nil</td>
    </tr>
    <tr>
      <td>backgroundColor</td>
      <td>UIColor?</td>
      <td>Background color for the push. If nil and gradientColors is not set, the default gradient is used.</td>
      <td>Default system gradient</td>
    </tr>
    <tr>
      <td>usePushAnimation</td>
      <td>Bool</td>
      <td>Whether to animate the push when shown.</td>
      <td>true</td>
    </tr>
    <tr>
      <td>titlePushColor</td>
      <td>UIColor?</td>
      <td>Color of the notification title text. Defaults to system white if nil.</td>
      <td>white</td>
    </tr>
    <tr>
      <td>messagePushColor</td>
      <td>UIColor?</td>
      <td>Color of the notification message text. Defaults to system white if nil.</td>
      <td>white</td>
    </tr>
    <tr>
      <td>titlePushFont</td>
      <td>UIFont?</td>
      <td>Font of the notification title text. Defaults to system font if nil.</td>
      <td>Default system font</td>
    </tr>
    <tr>
      <td>messagePushFont</td>
      <td>UIFont?</td>
      <td>Font of the notification message text. Defaults to system font if nil.</td>
      <td>Default system font</td>
    </tr>
  </tbody>
</table>

<Aside type="caution" title="Important">
- If the `useLiquidView` flag is enabled but the user's system version is lower than **iOS 26**, a regular `UIView`-based push will be shown instead.
- If your project is compiled with a Swift version **lower than 5.13**, the Liquid Glass effect will not be available at all — even on iOS 26. In that case, a blurred `UIVisualEffectView` (with `UIBlurEffect`) will be used instead on all devices.
</Aside>

**Summary:**
- Swift 5.13+ + iOS 26 → Liquid Glass
- Swift 5.13+ + iOS < 26 → Standard UIView
- Swift < 5.13 → Always blurred view (no Liquid Glass support)


**Example Usage:**

```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. Example of Foreground Push

This example demonstrates how to display a custom foreground push notification with `title`, `message`, `cards`, and `GIF animation`.

<figure style={{ textAlign: "center" }}>
  <video src="/ios-foreground-custom-5.webm" title="Example" autoplay loop muted playsinline />
  <figcaption>Pushwoosh foreground push with animated Liquid Glass view</figcaption>
</figure>

<figure style={{ textAlign: "center" }}>
  <video src="/ios-foreground-custom-1.webm" title="Example" autoplay loop muted playsinline />
  <figcaption>Pushwoosh foreground push with gif attachment</figcaption>
</figure>

<figure style={{ textAlign: "center" }}>
  <video src="/ios-foreground-custom-2.webm" title="Example" autoplay loop muted playsinline />
  <figcaption>Pushwoosh foreground push with card image</figcaption>
</figure>

<figure style={{ textAlign: "center" }}>
  <video src="/ios-foreground-custom-3.webm" title="Example" autoplay loop muted playsinline />
  <figcaption>Pushwoosh foreground push with a custom gradient, and custom title and message colors</figcaption>
</figure>

<figure style={{ textAlign: "center" }}>
  <video src="/ios-foreground-custom-4.webm" title="Example" autoplay loop muted playsinline />
  <figcaption>Pushwoosh foreground push with custom background, title and message fonts, and no animation</figcaption>
</figure>

That’s it. You have successfully configured custom foreground push notifications in iOS with Pushwoosh.