# 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 (opens new window). 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.

  • Swift
  • Objective C
UserSDK.default?.registerForRemoteNotifications(options: [.alert, .badge, .sound])

Handling notifications

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

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

the following line:

  • Swift
  • Objective C
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:

  • Swift
  • Objective C
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
      }

  }

the following line:

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.