Advanced
Verify AppDelegate code from below
#import "AppDelegate.h"
#import <UserNotifications/UserNotifications.h>
#import <UserNotificationsUI/UserNotificationsUI.h>
#import <Smartech/Smartech.h>
#import <SmartPush/SmartPush.h>
@interface AppDelegate () <UNUserNotificationCenterDelegate, SmartechDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[Smartech sharedInstance] initSDKWithDelegate:self withLaunchOptions:launchOptions];
[[SmartPush sharedInstance] registerForPushNotificationWithDefaultAuthorizationOptions];
[[Smartech sharedInstance] setDebugLevel:SMTLogLevelVerbose];
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[[SmartPush sharedInstance] didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[[SmartPush sharedInstance] didFailToRegisterForRemoteNotificationsWithError:error];
}
#pragma mark - UNUserNotificationCenterDelegate Methods
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
[[SmartPush sharedInstance] willPresentForegroundNotification:notification];
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
[[SmartPush 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
import SmartPush
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, SmartechDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
//...
Smartech.sharedInstance().initSDK(with: self, withLaunchOptions: launchOptions)
SmartPush.sharedInstance().registerForPushNotificationWithDefaultAuthorizationOptions()
Smartech.sharedInstance().setDebugLevel(.verbose)
UNUserNotificationCenter.current().delegate = self
//...
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
SmartPush.sharedInstance().didRegisterForRemoteNotifications(withDeviceToken: deviceToken)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
SmartPush.sharedInstance().didFailToRegisterForRemoteNotificationsWithError(error)
}
//MARK:- UNUserNotificationCenterDelegate Methods
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
SmartPush.sharedInstance().willPresentForegroundNotification(notification)
completionHandler([.alert, .badge, .sound])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
SmartPush.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 Netcore CE 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 Netcore CE 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.
Updated 2 months ago