In an automated integration, the AppDelegate replacement method sends method calls to your application’s real AppDelegate. If you do not want to rely on the AppDelegate replacement method, you can perform a manual integration.

In a manual integration, you add code to the AppDelegate.m file in your app instead of the MCEAppDelegate.m file in the SDK. Additionally, perform the following steps:

  • Set Other Linker Flags to -ObjC.
  • Copy MceConfig.json to your project. Modify MceConfig.json to include your app keys.
  • Remove the appDelegateClass section from MceConfig.json.
  • Add the Push Notifications Capability to the target settings. For instructions, see Setting up iOS apps (step 1) in Set up your iOS app in Apple.
  • Attach images, videos, and sound by following the instructions for adding the notification service. For instructions, see Adding media attachments to push notifications in iOS 10.

Attention:

  • The automated integration method of replacing AppDelegate is recommended for ease of integration and upgrading. Some integration issues might occur if you use the manual integration method.
  • When integrating manually, remember to remove the appDelegateClass section of your MceConfig.json file.
    • #import <IBMMobilePush/MCELocationClient.h>
      #import <IBMMobilePush/IBMMobilePush.h>
      
      -(instancetype)init
      {
          if(self = [super init])
          {
              [[MCESdk sharedInstance] handleApplicationLaunch];
          }
          return self;
      }
      
      #pragma mark Location Fetch Support
      - (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
      {
          if(MCESdk.sharedInstance.config.geofenceEnabled)
          {
              MCELocationClient * sync = [[MCELocationClient alloc] init];
              sync.fetchCompletionHandler = completionHandler;
              [sync scheduleSync];
           } else {
            completionHandler(UIBackgroundFetchResultNoData);
          }
      }
      
      - (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler
      {
          [[[MCELocationClient alloc] init] handleEventsForBackgroundURLSession: identifier completionHandler: completionHandler];
      }
      
      #pragma mark
      
      - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
      {
          [MCEEventService.sharedInstance sendPushEnabledEvent];
      }
      
      -(void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
          [[MCESdk sharedInstance]registerDeviceToken:deviceToken];
      
          if(![application respondsToSelector:@selector(registerUserNotificationSettings:)])
          {
              [MCEEventService.sharedInstance sendPushEnabledEvent];
          }
      }
      
      -(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
          [MCEEventService.sharedInstance sendPushEnabledEvent];
      }
      
      - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^_Nonnull __strong)())completionHandler
      {
          [[MCEInAppManager sharedInstance] processPayload: notification.userInfo];
          
          [[MCESdk sharedInstance] processDynamicCategoryNotification: notification.userInfo identifier:identifier userText: responseInfo[ UIUserNotificationActionResponseTypedTextKey]];
          completionHandler();
      }
      
      - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)withResponseInfo completionHandler:(void (^_Nonnull __strong)())completionHandler
      {
          [[MCEInAppManager sharedInstance] processPayload: userInfo];
          completionHandler();
      }
      
      - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler
      {
          [[MCEInAppManager sharedInstance] processPayload: userInfo];
          [[MCESdk sharedInstance] processCategoryNotification: userInfo identifier:identifier];
          completionHandler();
      }
      
      - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
      {
          [[MCEInAppManager sharedInstance] processPayload: userInfo];
          [[MCESdk sharedInstance] presentOrPerformNotification: userInfo];
      }
      
      - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
      {
          [[MCEInAppManager sharedInstance] processPayload: userInfo];
          [[MCESdk sharedInstance] presentDynamicCategoryNotification: userInfo];
          completionHandler(UIBackgroundFetchResultNewData);
      }
      
      - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
      {
          [[MCESdk sharedInstance] presentOrPerformNotification: notification.userInfo];
      }
      
      - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler
      {
          [[MCESdk sharedInstance] processDynamicCategoryNotification: notification.userInfo identifier:identifier userText: nil];
          completionHandler();
      }
      
      - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
          
      #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
          if([UNUserNotificationCenter class])
          {
              UNUserNotificationCenter * center = [UNUserNotificationCenter currentNotificationCenter];
              center.delegate=MCENotificationDelegate.sharedInstance;
              NSUInteger options = UNAuthorizationOptionAlert|UNAuthorizationOptionSound|UNAuthorizationOptionBadge|UNAuthorizationOptionCarPlay;
              [center requestAuthorizationWithOptions: options completionHandler:^(BOOL granted, NSError * _Nullable error) {
                  // Enable or disable features based on authorization.
                  NSLog(@"Notifications response %d, %@", granted, error);
                  [application registerForRemoteNotifications];
                  [center setNotificationCategories:nil];
                  
              }];
          }
          else
      #endif
              if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
              {
                  UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil];
                  [application registerUserNotificationSettings:settings];
                  [application registerForRemoteNotifications];
              }
              else {
                  //register to receive notifications iOS <8
                  UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
                  [application registerForRemoteNotificationTypes:myTypes];
              }
      
          return YES;
      }
      

      Go Back to the Mobile App Messaging home page.

      2 comments on"Manually integrating the iOS SDK using Objective-C"

      1. [[MCESdk sharedInstance]registerDeviceToken:deviceToken];

        If this fails first time due to network connectivity issue or any other issue, This is not returning mobile user id and push token on second and third retry.

      Join The Discussion

      Your email address will not be published. Required fields are marked *