logo
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:
swift
OneFlow.setupAnnouncementPushNotification([.alert, .badge, .sound], fromClass: AppDelegate.self)
Implement these blank methods in your AppDelegate:
swift
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:
    1. swift
      OneFlow.observer = self OneFlow.setupAnnouncementPushNotification([.alert, .badge, .sound], fromClass: AppDelegate.self)
  1. Implement the OneFlowObserver protocol in your AppDelegate or another suitable class to handle push token registration and notifications:
    1. swift
      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:
    1. swift
      OneFlow.pushToken = yourAPNSToken
  1. Handle incoming notifications and pass them to OneFlow for processing:
    1. swift
      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.

Handle Actions

Add in application(_:didFinishLaunchingWithOptions:):
swift
OneFlow.appDidLaunchedWith(launchOptions)

Handle Rich Push Notifications

To support push notifications with images:
  1. Navigate to File → New → Target and select "Notification Service Extension".
  1. Name the extension (e.g., NotificationService) and finish. Xcode generates a NotificationService class subclassing UNNotificationServiceExtension.
  1. Ensure deployment target matches your main app.
  1. In Signing & Capabilities, enable Background mode → Remote notifications if not already enabled.
    1. Image without caption
  1. Finally modify your extension file code as follows:
swift
class NotificationService: UNNotificationServiceExtension { var contentHandler: ((UNNotificationContent) -> Void)? var bestAttemptContent: UNMutableNotificationContent? override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { self.contentHandler = contentHandler guard let bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent), let apsDic = bestAttemptContent.userInfo["aps"] as? [String: Any], let alertDic = apsDic["alert"] as? [String: Any], let imageURLString = alertDic["icon"] as? String, let imageURL = URL(string: imageURLString) else { return } if let imageData = try? Data(contentsOf: imageURL), let attachment = UNNotificationAttachment.create(imageFileIdentifier: "image.jpg", data: imageData, options: nil) { bestAttemptContent.attachments = [attachment] } contentHandler(bestAttemptContent) } override func serviceExtensionTimeWillExpire() { if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent { contentHandler(bestAttemptContent) } } } extension UNNotificationAttachment { static func create(imageFileIdentifier: String, data: Data, options: [NSObject : AnyObject]?) -> UNNotificationAttachment? { let tempDirectory = URL(fileURLWithPath: NSTemporaryDirectory()) let imageFileIdentifier = imageFileIdentifier let fileURL = tempDirectory.appendingPathComponent(imageFileIdentifier) do { try data.write(to: fileURL) let imageAttachment = try UNNotificationAttachment(identifier: imageFileIdentifier, url: fileURL, options: options) return imageAttachment } catch { return nil } } }

Dashboard Configuration and Testing for Push Notifications

Navigate to your 1Flow dashboard:
  1. Go to Settings → Project → Push Notifications.
  1. Activate Apple iOS (APNs).
  1. Fill required details and save.
💡
Follow this link to generate p8 key.
Image without caption

Test Push Notifications in Production

To test push notifications, you will need an iOS device as push notifications do not work on simulators. Follow these steps:
  1. Open the application on your iOS device.
  1. Navigate to the 1Flow dashboard and create a new announcement.
  1. Select "Push" from the Channel list.
  1. Fill in the required details and click "Publish."
💡
Please note that it may take up to 5 minutes for the notification to be delivered.
Image without caption

Test Push Notification in Sandbox

For sandbox testing purposes, use the development API key. Remember to switch to the production API key before uploading your app to the App Store or distributing it via TestFlight.
  1. Enable Development Mode in the 1Flow dashboard: Go to Settings → Project → Push Notifications, and turn ON Development Mode. This mode automatically disables after 1 hour.
    1. Image without caption
  1. Create a new API key for Development: Navigate to Settings → Project → API keys, and click "New API key". Name it appropriately and select "Development" as the type.
When configuring the OneFlow SDK for sandbox testing, use your development API key as follows:
swift
OneFlow.configure(DEVELOPMENT_KEY)
💡
Before submitting your app to the App Store or deploying it via TestFlight, ensure you switch to the production API key in your code.