When you use the Pushwoosh SDK alongside another push notification provider (such as Firebase Cloud Messaging) in the same iOS app, a conflict can occur. Both SDKs may try to manage the UNUserNotificationCenterDelegate, which handles incoming push notifications. This conflict can prevent the Pushwoosh SDK from completing its device registration process, resulting in a null push token and failed test notifications.
To resolve this, you must use the notificationCenterDelegateProxy property in the Pushwoosh SDK. This allows you to assign your other provider's delegate to Pushwoosh, enabling both services to function correctly without interfering with each other.
Here is how to implement it in your AppDelegate.swift:
- Make sure you have a separate delegate class that handles the
UNUserNotificationCenterDelegatemethods for your other push provider. - In your
didFinishLaunchingWithOptionsmethod, after initializing Pushwoosh, set an instance of your other delegate class to thenotificationCenterDelegateProxyproperty.
Example Code:
import UIKit
import Pushwoosh
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, PWMessagingDelegate {
// An instance of the delegate for your OTHER push provider (e.g., Firebase).
let otherPushDelegate = OtherPushProviderDelegate()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Standard Pushwoosh setup
Pushwoosh.sharedInstance().applicationCode = "XXXXX-XXXXX"
Pushwoosh.sharedInstance().apiToken = "YOUR_API_TOKEN"
Pushwoosh.sharedInstance().delegate = self
// ** SOLUTION **
// Set the proxy to your other provider's delegate instance.
Pushwoosh.sharedInstance().notificationCenterDelegateProxy = otherPushDelegate
// Initialize your other push provider and set its delegate
// For example, with Firebase:
// FirebaseApp.configure()
// Messaging.messaging().delegate = otherPushDelegate
// Register for push notifications with Pushwoosh
Pushwoosh.sharedInstance().registerForPushNotifications()
return true
}
// ... rest of your AppDelegate implementation
}
// A separate class to handle delegate methods for your other push provider.
class OtherPushProviderDelegate: NSObject, UNUserNotificationCenterDelegate {
// Implement the UNUserNotificationCenterDelegate methods for your other provider here.
// For example:
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
// Handle foreground notifications
completionHandler([.alert, .sound, .badge])
}
}
By setting the notificationCenterDelegateProxy, you ensure that Pushwoosh can properly receive the device token and register the device while still allowing your other push provider to handle its own notifications.
Comments
0 comments
Please sign in to leave a comment.