Receiving a notification

  • User.com SDK uses Firebase Cloud Messaging to send push notifications to your users directly from your app.

    Configure FCM

    If you don’t have FCM integrated with your app yet you have to configure Push Notification by visiting https://firebase.google.com/docs/ios/setup. Firebase SDK has been added to your project and it’s configuration is handled by User.com SDK so you don’t have to add it to your app manually or configure it, but

  • Register for notifications

    After configuring FCM, invoke this method in order to register for notifications, it will prompt the user to allow push notifications for your app if he hasn’t already.

    UserSDK.default?.registerForRemoteNotifications(options: [.alert, .badge, .sound])
  • Handling notifications

    In order to receive in-app messages and to send information clicks in your push notifications you have to allow the SDK to handle notifications. You can do so by adding to this method in your AppDelegate file:

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)

    the following line

    UserSDK.default?.handleNotification(userInfo: userInfo)

    After updating the code the SDK will handle in-app messages sent from User.com panel. In case if there is any other notification our SDK receives it allows to register classes to receive updates about those notifications by implementing RemoteNotificationDelegate:

    class MainViewController: TableViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            registerForNotificationsUpdates()
        }
    }
    
    extension MyViewController: RemoteNotificationDelegate {
        private func registerForNotificationsUpdates() {
            // register this view controller as a receiver for notifications
            UserSDK.default?.notificationDelegate = self
        }
    
        func didReceiveRemoteNotification(with id: String, data: [AnyHashable : Any]) {
            //handle remote notification
        }
    }