How to Avoid Common Push Notification Issues on iOS Devices Using Flutter, Objective-C, and MoEngage-iOS-SDK (Versions 7.x.x , 8.x.x, 9.x.x)?

Problem

Common issues with Push notifications, including failed delivery, screen navigation, deep linking, and rich landing, are occurring on iOS devices using Flutter, Objective-C, and MoEngage-iOS-SDK (Versions 7.x.x, 8.x.x, 9.x.x).

Solution

Perform the following steps:

  1. Disable Firebase Proxy:
    • If you are not using Firebase push notifications, disable the Firebase proxy by adding the FirebaseAppDelegateProxyEnabled key in info.plist with the value Boolean = False/NO.
    • Test the push notification. If it works, no further action is needed.
    • If you are using Firebase push notifications, skip this step and proceed with the following steps.
  2. Disable MoEngage Proxy:
    • Add MoEngageAppDelegateProxyEnabled key in info.plist with the value Boolean = false/NOboolean.png
  3. Override didRegisterForRemoteNotificationsWithDeviceToken Function:
    • Override the didRegisterForRemoteNotificationsWithDeviceToken function of the AppDelegate.m file.
      Objective-C
      - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
      { 
        [super application: application didRegisterForRemoteNotificationsWithDeviceToken: deviceToken]; 
        
        //7.xx version
        [[MoEngage sharedInstance] setPushToken:deviceToken];
        
        //8.xx version
        [[MOMessaging sharedInstance] setPushToken:deviceToken];
        
        //9.xx version
        [[MoEngageSDKMessaging sharedInstance] setPushToken:deviceToken];
      }
  4. Override UNUserNotificatoinCenterDelegate Functions:
    • Override the UNUserNotificatoinCenterDelegate functions in the AppDelegate.m file.
      Objective-C
      //Try without willPresent if it works good to go! else override it
      - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
        if (notification.request.content.userInfo != nil) {
          NSDictionary *dictionary = notification.request.content.userInfo;
          if (dictionary[@"moengage"] != nil) {
            completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
          } else {
            [super userNotificationCenter: center willPresentNotification: notification withCompletionHandler:completionHandler];
          }
      }
      
      - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
      {
        [super userNotificationCenter: center didReceiveNotificationResponse: response withCompletionHandler: completionHandler];
        
        //7.xx version
        [[MoEngage sharedInstance] userNotificationCenter:center didReceiveNotificationResponse:response];
      
        //8.xx version
        [[MOMessaging sharedInstance] userNotificationCenter:center didReceive:response];
        
        //9.xx version
        [[MoEngageSDKMessaging sharedInstance] userNotificationCenter:center didReceive:response];
        
        completionHandler();
      }

       

Was this article helpful?
0 out of 0 found this helpful

How can we improve this article?