ข้ามไปยังเนื้อหา

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

Anchor link to

Adding Pushwoosh_SHOW_ALERT = false to your Info.plist.

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

2. Integrating the PushwooshForegroundPush Module

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. Add PushwooshForegroundPush Configuration in 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)
}
}
}

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

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

Parameters:

  1. style (PWForegroundPushStyle)
  • Currently, only style1 is available.
  1. duration (Int)
  • Specifies how long the notification will be displayed before disappearing (in seconds).
  1. vibration (PWForegroundPushHapticFeedback)
  • Controls the haptic feedback when the notification is shown. Available options:
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
  1. disappearedPushAnimation (PWForegroundPushDisappearedAnimation)
  • Push disappearance animation
case balls = 0
case regularPush

4. Implementing didTapForegroundPush Delegate Method

Anchor link to

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

// 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

Anchor link to

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.

PropertyTypeDescriptionDefault
useLiquidViewBoolUse Liquid Glass view on iOS 26.false
gradientColors[UIColor]?Optional array of colors for a gradient background.nil
backgroundColorUIColor?Background color for the push. If nil and gradientColors is not set, the default gradient is used.Default system gradient
usePushAnimationBoolWhether to animate the push when shown.true
titlePushColorUIColor?Color of the notification title text. Defaults to system white if nil.white
messagePushColorUIColor?Color of the notification message text. Defaults to system white if nil.white
titlePushFontUIFont?Font of the notification title text. Defaults to system font if nil.Default system font
messagePushFontUIFont?Font of the notification message text. Defaults to system font if nil.Default system font

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:

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

Anchor link to

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

Example
Pushwoosh foreground push with animated Liquid Glass view
Example
Pushwoosh foreground push with gif attachment
Example
Pushwoosh foreground push with card image
Example
Pushwoosh foreground push with a custom gradient, and custom title and message colors
Example
Pushwoosh foreground push with custom background, title and message fonts, and no animation

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