1Flow supports Push Notification Announcements, enabling you to trigger actions with push notifications.

Enable Push Notifications

Follow this Apple guide to enable push notifications for your app - Enable the push notifications capability.

Register Your App for a Device Token

1Flow provides several ways to register your app for Announcement push notifications and retrieve a device token.

Setup OneFlow Push Notifications for Sole Sender

If 1Flow is the only notification sender:

OneFlow.setupAnnouncementPushNotification([.alert, .badge, .sound], fromClass: AppDelegate.self)

Implement these blank methods in your AppDelegate:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {}

Setup OneFlow Push Notifications with an Additional Sender

If your app supports push notifications from both 1Flow and another server, follow these steps to integrate with an additional sender:

  1. Initialize OneFlow with an observer to receive push tokens:

    OneFlow.observer = self
    OneFlow.setupAnnouncementPushNotification([.alert, .badge, .sound], fromClass: AppDelegate.self)
    
  2. Implement the OneFlowObserver protocol in your AppDelegate or another suitable class to handle push token registration and notifications:

    extension AppDelegate: OneFlowObserver {
    
        func oneFlowDidGeneratePushToken(_ pushToken: String) {
            // Implement code to send the push token to the additional server
        }
    
        func oneFlowDidFailedToGeneratePushToken(_ error: Error) {
            // Handle error when push token generation fails
        }
    
        func oneFlowNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
            // Handle user responses to notifications
        }
    
        func oneFlowNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
            // Handle notifications when the app is in the foreground
        }
    }
    

Setup OneFlow Push Notifications with Firebase or Other Third-Party SDKs

If your app uses Firebase or other SDKs that manage UIApplicationDelegate methods for push notifications, ensure there's no conflict with OneFlow:

  1. Pass the push token obtained from Firebase to OneFlow:

    OneFlow.pushToken = yourAPNSToken
    
  2. Handle incoming notifications and pass them to OneFlow for processing:

    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        let userInfo = notification.request.content.userInfo
        OneFlow.appWillPresentRemoteNotification(userInfo)
        // Handle other presentation options as needed
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        OneFlow.appDidReceiveResponseForRemoteNotification(userInfo)
        // Handle other responses as needed
    }
    

Ensure these steps are integrated correctly into your project based on whether you're supporting an additional sender or using Firebase or other third-party SDKs alongside OneFlow for push notifications.