These docs are for v1.0. Click to read the latest docs for v2.0.

Other changes in AppDelegate class

Register For Remote Notifications

In order to receive push notifications you need to send the device token you received in method didRegisterForRemoteNotificationsWithDeviceToken to Smartech. Refer the following code:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  [[NetCoreInstallation sharedInstance] netCorePushRegisteration:[[NetCoreSharedManager sharedInstance] getIdentity] withDeviceToken:deviceToken Block:nil];
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  NetCoreInstallation.sharedInstance()?.netCorePushRegisteration(NetCoreSharedManager.sharedInstance().getIdentity(), withDeviceToken: deviceToken, block:nil)
}

Handle Notifications

To handle local notifications in OS version below 10.0 implement the following code in application:didReceiveLocalNotification:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
  [[NetCorePushTaskManager sharedInstance] didReceiveLocalNotification:notification.userInfo];
}
func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
  NetCorePushTaskManager.sharedInstance().didReceiveLocalNotification(notification.userInfo!)
}

To handle notifications in OS version above 10.0 implement the following code in delegate methods of UNUserNotificationCenter

First import following frameworks provided by apple for UNUserNotificationCenter

#import <UserNotifications/UserNotifications.h>
#import <UserNotificationsUI/UserNotificationsUI.h>
import UserNotifications
import UserNotificationsUI

Delegate methods to be used of UNUserNotificationCenter:

  1. userNotificationCenter:willPresentNotification:withCompletionHandler
  2. userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler

To implement these methods you add following lines in didFinishLaunchingWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  //...
  [[NetCoreSharedManager sharedInstance] setUpAppGroup:kAppGroup];
  [[NetCoreSharedManager sharedInstance] handleApplicationLaunchEvent:launchOptions forApplicationId:kSmartechAppID];
  [NetCorePushTaskManager sharedInstance].delegate = (id)self;
  if (@available(iOS 10.0, *)) {
    [UNUserNotificationCenter currentNotificationCenter].delegate = self;
  }
  //...
  return YES;
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    //...
    NetCoreSharedManager.sharedInstance().setUpAppGroup(kAppGroup)        
    NetCoreSharedManager.sharedInstance().handleApplicationLaunchEvent(launchOptions, forApplicationId: kSmartechAppID)
    NetCorePushTaskManager.sharedInstance().delegate = self
    if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().delegate = self
     }
    //...
    return true
}

Defining the UNUserNotificationCenterDelegate protocol in AppDelegate

@interface AppDelegate () <UNUserNotificationCenterDelegate>

@end
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {

}

Implementing netcore methods in UNUserNotificationCenterDelegate methods

#pragma mark - UNUserNotificationCenter Delegate Methods
  
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler  API_AVAILABLE(ios(10.0)) {
  [[NetCorePushTaskManager sharedInstance] userNotificationWillPresentNotification:notification];
  completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler  API_AVAILABLE(ios(10.0)) {
  //This method should be used in SDK v2.4.0 and above.
  [[NetCorePushTaskManager sharedInstance] userNotificationdidReceiveNotificationResponse:response];
  completionHandler();
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
  NetCorePushTaskManager.sharedInstance().userNotificationWillPresent(notification)
  completionHandler([.alert, .badge, .sound])
}
    
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
  //This method should be used in SDK v2.4.0 and above.
  NetCorePushTaskManager.sharedInstance().userNotificationdidReceive(response)
  completionHandler()
}

Check logs of Netcore SDK

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

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  //...
  [[NetCoreSharedManager sharedInstance] setUpAppGroup:kAppGroup];
  [[NetCoreSharedManager sharedInstance] handleApplicationLaunchEvent:launchOptions forApplicationId:kSmartechAppID];
  [[NetCoreSharedManager sharedInstance] setDebugLevel:NCLogLevelVerbose];
  
  if (@available(iOS 10.0, *)) {
    [UNUserNotificationCenter currentNotificationCenter].delegate = self;
  }
  [NetCorePushTaskManager sharedInstance].delegate = (id)self;
  //...
  return YES;
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  //...
  NetCoreSharedManager.sharedInstance().setUpAppGroup(kAppGroup)
  NetCoreSharedManager.sharedInstance().handleApplicationLaunchEvent(launchOptions, forApplicationId: kAppId)
  NetCoreSharedManager.sharedInstance().setDebugLevel(.verbose)
  
  if #available(iOSApplicationExtension 10.0, *) {
    UNUserNotificationCenter.current().delegate = self
  }
  NetCorePushTaskManager.sharedInstance().delegate = self
  //...
  return true
}

🚧

Note:

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

Verify full code of AppDelegate with Smartech SDK

#import "AppDelegate.h"

#import <NetCorePush/NetCorePush.h>
#import <UserNotifications/UserNotifications.h>
#import <UserNotificationsUI/UserNotificationsUI.h>
  
NSString *const kSmartechAppID = @"APP ID THAT YOU GET FROM SMARTECH PANEL";
NSString *const kAppGroup = @"group.com.yourcompanyname.productname";

@interface AppDelegate () <UNUserNotificationCenterDelegate>
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // Override point for custom{
  //...
  [[NetCoreSharedManager sharedInstance] setUpAppGroup:kAppGroup];
  [[NetCoreSharedManager sharedInstance] handleApplicationLaunchEvent:launchOptions forApplicationId:kSmartechAppID];
  [[NetCoreSharedManager sharedInstance] setDebugLevel:NCLogLevelVerbose];
  [NetCorePushTaskManager sharedInstance].delegate = (id)self;
  if (@available(iOS 10.0, *)) {
    [UNUserNotificationCenter currentNotificationCenter].delegate = self;
  }
  //...
  return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  [[NetCoreInstallation sharedInstance] netCorePushRegisteration:[[NetCoreSharedManager sharedInstance] getIdentity] withDeviceToken:deviceToken Block:nil];
}

//Method for supporting os version below 10
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
  [[NetCorePushTaskManager sharedInstance] didReceiveLocalNotification:notification.userInfo];
}

#pragma mark - UNUserNotificationCenterDelegate Methods
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler  API_AVAILABLE(ios(10.0)) {
  [[NetCorePushTaskManager sharedInstance] userNotificationWillPresentNotification:notification];
  completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler  API_AVAILABLE(ios(10.0) {
  [[NetCorePushTaskManager sharedInstance] userNotificationdidReceiveNotificationResponse:response];
  completionHandler();
}

@end
import UIKit
import NetCorePush
import UserNotifications
import UserNotificationsUI

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {

var window: UIWindow?
    
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    //...
    NetCoreSharedManager.sharedInstance().setUpAppGroup(kAppGroup)        
    NetCoreSharedManager.sharedInstance().handleApplicationLaunchEvent(launchOptions, forApplicationId: kSmartechAppID)
  	NetCoreSharedManager.sharedInstance().setDebugLevel(.verbose)
    NetCorePushTaskManager.sharedInstance().delegate = self
    if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().delegate = self
     }
    //...
    return true
}
    
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  NetCoreInstallation.sharedInstance()?.netCorePushRegisteration(NetCoreSharedManager.sharedInstance().getIdentity(), withDeviceToken: deviceToken, block:nil)
}
  
//Method for supporting os version below 10
func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
  NetCorePushTaskManager.sharedInstance().didReceiveLocalNotification(notification.userInfo!)
}
  
//MARK:- UNUserNotificationCenterDelegate
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
  NetCorePushTaskManager.sharedInstance().userNotificationWillPresent(notification)
  completionHandler([.alert, .badge, .sound])
}
    
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
  //This method should be used in SDK v2.4.0 and above.
  NetCorePushTaskManager.sharedInstance().userNotificationdidReceive(response)
  completionHandler()
}
  
}