export const appDelegateHeader = "AppDelegate.h" export const importSmartPush = `#import `; export const interfaceDelegate = "@interface AppDelegate"; export const smartechPushReactNative = { fileImport: '#import "SmartechPushReactnative.h"', importSmartechBaseReactNative: '#import "SmartechBaseReactNative.h"', userNotification: "#import ", userNotificationUI: "#import ", interfaceLine: [ "@interface AppDelegate () ", "", "@end", ].join("\n") } export const smartechPushNotificationDelegateSnippet = (autoAskNotificationPermission?: boolean): string[] => { const snippet: string[] = [ "[UNUserNotificationCenter currentNotificationCenter].delegate = self;", ]; // Default behavior: if autoAskNotificationPermission is undefined/null, include the registration call (backward compatible) // If explicitly set to true, include it // If explicitly set to false, exclude it const shouldAutoAsk = autoAskNotificationPermission === undefined || autoAskNotificationPermission === null || autoAskNotificationPermission === true; if (shouldAutoAsk) { snippet.push("[[SmartPush sharedInstance] registerForPushNotificationWithDefaultAuthorizationOptions];"); } return snippet; } export const registerForNotificationSnippet = { registerString: "[[SmartPush sharedInstance] didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];", registerNotificationFunction: [ "- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {", "[[SmartPush sharedInstance] didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];", "}", ].join("\n") } export const failToRegisterForNotificationSnippet = { registerString: "[[SmartPush sharedInstance] didFailToRegisterForRemoteNotificationsWithError:error];", failToRegisterFunction: [ "- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {", "[[SmartPush sharedInstance] didFailToRegisterForRemoteNotificationsWithError:error];", "}" ].join("\n") } export const userNotificationDelegateSnippet = [ " #pragma mark - UNUserNotificationCenterDelegate Methods", "- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {", " [[SmartPush sharedInstance] willPresentForegroundNotification:notification];", " completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);", "}", "\n", "- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {", " [[SmartPush sharedInstance] didReceiveNotificationResponse:response];", "\n", " completionHandler();", "}", "\n", ].join("\n") // Swift imports and constants export const swiftImports = { smartPushImport: 'import SmartPush', userNotificationsImport: 'import UserNotifications' } // Bridging header imports for Swift projects export const swiftBridgingHeaderImports = [ '#import "SmartechPushReactnative.h"', '#import "SmartechBaseReactNative.h"' ] export const swiftPushDelegateSnippet = (autoAskNotificationPermission?: boolean): string[] => { const snippet: string[] = [ " UNUserNotificationCenter.current().delegate = self", ]; // Default behavior: if autoAskNotificationPermission is undefined/null, include the registration call (backward compatible) // If explicitly set to true, include it // If explicitly set to false, exclude it const shouldAutoAsk = autoAskNotificationPermission === undefined || autoAskNotificationPermission === null || autoAskNotificationPermission === true; if (shouldAutoAsk) { snippet.push(" SmartPush.sharedInstance().registerForPushNotification(authorizationOptions: [.alert, .badge, .sound])"); } return snippet; } export const swiftRegisterForNotificationSnippet = { registerString: " SmartPush.sharedInstance().didRegisterForRemoteNotifications(withDeviceToken: deviceToken)", registerNotificationFunction: [ " public override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {", " super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)", " SmartPush.sharedInstance().didRegisterForRemoteNotifications(withDeviceToken: deviceToken)", " }" ].join("\n") } export const swiftFailToRegisterForNotificationSnippet = { registerString: " SmartPush.sharedInstance().didFailToRegisterForRemoteNotifications(withError: error)", failToRegisterFunction: [ " public override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {", " super.application(application, didFailToRegisterForRemoteNotificationsWithError: error)", " SmartPush.sharedInstance().didFailToRegisterForRemoteNotificationsWithError(error)", " }" ].join("\n") } export const swiftUserNotificationDelegateSnippet = [ "", " // MARK: - UNUserNotificationCenterDelegate Methods", " public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {", " SmartPush.sharedInstance().willPresentForegroundNotification(notification)", " completionHandler([.sound, .alert, .badge])", " }", "", " public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {", " DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {", " SmartPush.sharedInstance().didReceive(response)", " }", " completionHandler()", " }", "" ].join("\n") export const NSE = { folderName: "SmartechNSE", targetName: 'SmartechNSE', sourceFileName: 'NotificationService.m', extFiles: [ 'NotificationService.h', 'SmartechNSE.entitlements', 'SmartechNSE-Info.plist', ], podFileRegex: /target 'SmartechNSE'/, groupRegex: /{{MY_NSE_GROUP}}/gm, podFileSnippet: ` #service extension target target 'SmartechNSE' do use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks'] use_frameworks! :linkage => ENV['USE_FRAMEWORKS'].to_sym if ENV['USE_FRAMEWORKS'] # Pods for 'SmartechNSE' pod 'SmartPush-iOS-SDK', '~> 3.5.1' end` } export const NCE = { folderName: "SmartechNCE", targetName: 'SmartechNCE', sourceFileName: 'NotificationViewController.m', extFiles: [ 'NotificationViewController.h', 'SmartechNCE.entitlements', 'SmartechNCE-Info.plist', ], storyboardDir: 'Base.lproj', storyboardFile: 'MainInterface.storyboard', podFileRegex: /target 'SmartechNCE'/, groupRegex: /{{MY_NCE_GROUP}}/gm, podFileSnippet: ` #content extension target target 'SmartechNCE' do use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks'] use_frameworks! :linkage => ENV['USE_FRAMEWORKS'].to_sym if ENV['USE_FRAMEWORKS'] # Pods for 'SmartechNCE' pod 'SmartPush-iOS-SDK', '~> 3.5.1' end` } export const NSE_TARGET_NAME = 'SmartechNSE'; export const NCE_TARGET_NAME = 'SmartechNCE'; export const NSE_SOURCE_FILE = 'NotificationService.m'; export const NCE_SOURCE_FILE = 'NotificationViewController.m'; export const NSE_EXT_FILES = [ 'NotificationService.h', 'SmartechNSE.entitlements', 'SmartechNSE-Info.plist', ]; export const NCE_EXT_FILES = [ 'NotificationViewController.h', 'SmartechNCE.entitlements', 'SmartechNCE-Info.plist', ]; export const NCE_STORYBOARD_NAME = 'Base.lproj'; export const NCE_STORYBOARD_FILES = 'MainInterface.storyboard'; export const GROUP_IDENTIFIER_TEMPLATE_REGEX = /{{GROUP_IDENTIFIER}}/gm; export const BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = /{{BUNDLE_SHORT_VERSION}}/gm; export const BUNDLE_VERSION_TEMPLATE_REGEX = /{{BUNDLE_VERSION}}/gm; export const NCE_GROUP_REGEX = /{{NCE_GROUP}}/gm; export const NSE_GROUP_REGEX = /{{NSE_GROUP}}/gm; export const DEFAULT_BUNDLE_VERSION = '1'; export const DEFAULT_BUNDLE_SHORT_VERSION = '1.0'; export const IPHONEOS_DEPLOYMENT_TARGET = '13.0'; export const TARGETED_DEVICE_FAMILY = '"1,2"'; export const NSE_PODFILE_REGEX = /target 'SmartechNSE'/; export const NCE_PODFILE_REGEX = /target 'SmartechNCE'/; // Swift-specific extension constants export const SWIFT_NSE = { folderName: "SmartechNSE", targetName: 'SmartechNSE', sourceFileName: 'NotificationService.swift', extFiles: [ 'SmartechNSE.entitlements', 'SmartechNSE-Info.plist', ], podFileRegex: /target 'SmartechNSE'/, groupRegex: /{{MY_NSE_GROUP}}/gm, podFileSnippet: ` #service extension target target 'SmartechNSE' do use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks'] use_frameworks! :linkage => ENV['USE_FRAMEWORKS'].to_sym if ENV['USE_FRAMEWORKS'] # Pods for 'SmartechNSE' pod 'SmartPush-iOS-SDK' end` } export const SWIFT_NCE = { folderName: "SmartechNCE", targetName: 'SmartechNCE', sourceFileName: 'NotificationViewController.swift', extFiles: [ 'SmartechNCE.entitlements', 'SmartechNCE-Info.plist', ], storyboardDir: 'Base.lproj', storyboardFile: 'MainInterface.storyboard', podFileRegex: /target 'SmartechNCE'/, groupRegex: /{{MY_NCE_GROUP}}/gm, podFileSnippet: ` #content extension target target 'SmartechNCE' do use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks'] use_frameworks! :linkage => ENV['USE_FRAMEWORKS'].to_sym if ENV['USE_FRAMEWORKS'] # Pods for 'SmartechNCE' pod 'SmartPush-iOS-SDK' end` }