Silent Push Notification

Implement didReceiveRemoteNotification method for Silent Push Notification (3.0.2 onwards)
This will be used for scheduled push notification feature.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler {
   [[Smartech sharedInstance] didReceiveRemoteNotification:userInfo withCompletionHandler:^(BOOL finishedScheduling) {
        if (finishedScheduling) {
            completionHandler(UIBackgroundFetchResultNewData);
        }
        else {
            completionHandler(UIBackgroundFetchResultNoData);
        }
    }];
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
      Smartech.sharedInstance().didReceiveRemoteNotification(userInfo, withCompletionHandler: completionHandler)

    }

Handle Deep Link and Custom Payload

To handle URL/Deeplink/Universal Link and custom payload the developer needs to implement one delegate method named handleDeeplinkActionWithURLString of SmartechDelegate in AppDelegate.m which will provide the URL/Deeplink/Universal Link and custom payload.
Implement SmartechDelegate and confirm the protocol of it.

@interface AppDelegate () <UNUserNotificationCenterDelegate, SmartechDelegate>

@end
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, SmartechDelegate {

}

Implement SmartechDelegate method

#pragma mark - SmartechDelegate Method
- (void)handleDeeplinkActionWithURLString:(NSString *)deeplinkURLString andCustomPayload:(NSDictionary *_Nullable)customPayload {
  //...
  NSLog(@"Deeplink: %@", deeplinkURLString);
  NSLog(@"Custom Payload: %@", customPayload);
  //...
}
//MARK:- SmartechDelegate Method
func handleDeeplinkAction(withURLString deeplinkURLString: String, andCustomPayload customPayload: [AnyHashable : Any]?) {
  //...
  print("Deeplink: \(deeplinkURLString)")
  if customPayload != nil {
    print("Custom Payload: \(customPayload!)")
  }
  //...
}

Verify AppDelegate code from below

#import "AppDelegate.h"

#import <UserNotifications/UserNotifications.h>
#import <UserNotificationsUI/UserNotificationsUI.h>
#import <Smartech/Smartech.h>
  
@interface AppDelegate () <UNUserNotificationCenterDelegate, SmartechDelegate>

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
  [[Smartech sharedInstance] initSDKWithDelegate:self];
  [[Smartech sharedInstance] registerForPushNotificationWithDefaultAuthorizationOptions];
  [[Smartech sharedInstance] setDebugLevel:SMTLogLevelVerbose];
  [UNUserNotificationCenter currentNotificationCenter].delegate = self;
  
  return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  [[Smartech sharedInstance] didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
  [[Smartech sharedInstance] didFailToRegisterForRemoteNotificationsWithError:error];
}

#pragma mark - UNUserNotificationCenterDelegate Methods
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
  [[Smartech sharedInstance] willPresentForegroundNotification:notification];
  completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
  [[Smartech sharedInstance] didReceiveNotificationResponse:response];
  completionHandler();
}

#pragma mark - SmartechDelegate Method
- (void)handleDeeplinkActionWithURLString:(NSString *)deeplinkURLString andCustomPayload:(NSDictionary *_Nullable)customPayload {
  //...
  NSLog(@"Deeplink: %@", deeplinkURLString);
  NSLog(@"Custom Payload: %@", customPayload);
  //...
}

@end
import UIKit
import UserNotifications
import UserNotificationsUI
import Smartech

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, SmartechDelegate {
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        //...
        Smartech.sharedInstance().initSDK(with: self)
        Smartech.sharedInstance().registerForPushNotificationWithDefaultAuthorizationOptions()
        Smartech.sharedInstance().setDebugLevel(.verbose)
        UNUserNotificationCenter.current().delegate = self
        //...
        return true
    }
    
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Smartech.sharedInstance().didRegisterForRemoteNotifications(withDeviceToken: deviceToken)
    }
    
    func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        Smartech.sharedInstance().didFailToRegisterForRemoteNotificationsWithError(error)
    }
    
    //MARK:- UNUserNotificationCenterDelegate Methods
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        Smartech.sharedInstance().willPresentForegroundNotification(notification)
        completionHandler([.alert, .badge, .sound])
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        Smartech.sharedInstance().didReceive(response)
        completionHandler()
    }
    
    //MARK:- SmartechDelegate Method
    func handleDeeplinkAction(withURLString deeplinkURLString: String, andCustomPayload customPayload: [AnyHashable : Any]?) {
        print("Deeplink: \(deeplinkURLString)")
        if customPayload != nil {
            print("Custom Payload: \(customPayload!)")
        }
    }
}

Identifying CEE Notifications

if ([[Smartech sharedInstance] isNotificationFromSmartech:(nonnull NSDictionary *)]) {
  
}
if Smartech.sharedInstance().isNotification(fromSmartech: [AnyHashable : Any]) {
  
}

Get GUID or Device token

If you need any additional information like device token or device GUID you can implement the following methods

[[Smartech sharedInstance] getDevicePushToken];
[[Smartech sharedInstance] getDeviceGuid];
Smartech.sharedInstance().getDevicePushToken()
Smartech.sharedInstance().getDeviceGuid()
SmartechSDK.getDevicePushToken((error, devicePushToken) => {
      //Grab the devicePushToken   
});

Debugging

To check the logs of CEE SDK, you need to implement a method named setDebugLevel in AppDelegate class in method didFinishLaunchingWithOptions.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  //...
  [[Smartech sharedInstance] setDebugLevel:SMTLogLevelVerbose];
  //...
  return YES;
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  //...
  Smartech.sharedInstance().initSDK(withDelegate: self)
  Smartech.sharedInstance().registerForPushNotificationWithDefaultAuthorizationOptions()
  Smartech.sharedInstance().setDebugLevel(.verbose)
  //...
  return true
}

🚧

Note:

It is recommended to change the log level to SMT_LOG_LEVEL_NONE before uploading the app to the App Store.


Next

You can choose to go back