/
ios.ts
98 lines (80 loc) · 4.49 KB
/
ios.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const finder = require('find-package-json');
const path = require('path');
const f = finder(__dirname);
let pluginPackageRoot = f.next().filename;
// This is the path to the root of the customerio-expo-plugin package
pluginPackageRoot = path.dirname(pluginPackageRoot);
export const LOCAL_PATH_TO_RN_SDK = path.join(
pluginPackageRoot,
'../customerio-reactnative'
)
export const LOCAL_PATH_TO_CIO_NSE_FILES = path.join(
pluginPackageRoot,
'src/helpers/native-files/ios'
);
export function getRelativePathToRNSDK(currentFile: string) {
return path.relative(path.dirname(currentFile), LOCAL_PATH_TO_RN_SDK);
}
export const IOS_DEPLOYMENT_TARGET = '13.0';
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 CIO_DIDFINISHLAUNCHINGMETHOD_REGEX =
/(- \(BOOL\)application:\(UIApplication \*\)application didFinishLaunchingWithOptions:\(NSDictionary \*\)launchOptions(\s|\n)*?\{)((.|\n)*)\[super(\s)application:application(\s)didFinishLaunchingWithOptions:launchOptions\];/;
export const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX =
/return \[super application:application didFailToRegisterForRemoteNotificationsWithError:error\];/;
export const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX =
/(- \(void\)application:\(UIApplication \*\)application didFailToRegisterForRemoteNotificationsWithError:\(NSError \*\)error(\s|\n)*?\{)(.|\n){2}.*\n\}/;
export const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX =
/return \[super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken\];/;
export const CIO_APPDELEGATEDECLARATION_REGEX =
/@implementation AppDelegate(.|\n)/;
export const CIO_APPDELEGATEHEADER_REGEX =
/@interface AppDelegate : EXAppDelegateWrapper <RCTBridgeDelegate>/;
export const DEFAULT_BUNDLE_VERSION = '1';
export const DEFAULT_BUNDLE_SHORT_VERSION = '1.0';
export const CIO_TARGET_NAME = 'CustomerIOSDK';
export const CIO_NOTIFICATION_TARGET_NAME = 'NotificationService';
export const CIO_APPDELEGATEHEADER_SNIPPET = `
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : EXAppDelegateWrapper <RCTBridgeDelegate, UNUserNotificationCenterDelegate>
`;
export const CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET = `
CIOAppPushNotificationsHandler* pnHandlerObj = [[CIOAppPushNotificationsHandler alloc] init];
`;
export const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET = `
[super application:application didFailToRegisterForRemoteNotificationsWithError:error];
[pnHandlerObj application:application error:error];
`;
export const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET = `
[super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
return [pnHandlerObj application:application deviceToken:deviceToken];
`;
export const CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET = `
// Register for push notifications
[pnHandlerObj registerPushNotification:self];
`;
// Enable push handling - notification response
export const CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET = `
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {
[pnHandlerObj userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}`;
// Foreground push handling
export const CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET = `
// show push when the app is in foreground
- (void)userNotificationCenter:(UNUserNotificationCenter* )center willPresentNotification:(UNNotification* )notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
completionHandler( UNNotificationPresentationOptionAlert + UNNotificationPresentationOptionSound);
}`;
export const CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = `
@objc(registerPushNotification:)
public func registerPushNotification(withNotificationDelegate notificationDelegate: UNUserNotificationCenterDelegate) {
let center = UNUserNotificationCenter.current()
center.delegate = notificationDelegate
center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
if error == nil{
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}
}`;