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])
    UNAuthorizationOptions options = UNAuthorizationOptionAlert + UNAuthorizationOptionSound;
    [[UserSDK default] registerForRemoteNotificationsWithOptions:options notificationDelegate:self];
  • 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:

    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
        }
    }
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
    
    [[UserSDK default] handleNotificationWithUserInfo:userInfo];
    
    @interface MainViewController () <RemoteNotificationDelegate>
    
    @end
    
    @implementation MainViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
         // register this view controller as a receiver for notifications
        [UserSDK default].notificationDelegate = self;
    }
    
    - (void)didReceiveRemoteNotificationWith:(NSString *)id data:(NSDictionary *)data {
        //handle remote notification
    }
    
    @end