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

    You can register classes to receive notification updates by implementing RemoteNotificationDelegate:

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

    SDK will use only notifications containing User.com tag, so if you have already FCM in your project, SDK will not interfere with existing notifications.