@allboatsrise/expo-marketingcloudsdk 45.0.0 → 46.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <UIKit/UIKit.h>
3
+ #import <UserNotifications/UserNotifications.h>
4
+ #import <ExpoModulesCore/EXSingletonModule.h>
5
+ #import <ExpoModulesCore/EXModuleRegistryConsumer.h>
6
+
7
+ NS_ASSUME_NONNULL_BEGIN
8
+
9
+ @interface EXMarketingCloudSdk : EXSingletonModule <UIApplicationDelegate, UNUserNotificationCenterDelegate, EXModuleRegistryConsumer>
10
+
11
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions;
12
+ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler;
13
+
14
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler;
15
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler;
16
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(nullable UNNotification *)notification;
17
+
18
+ @end
19
+
20
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,101 @@
1
+ #import <MarketingCloudSDK/MarketingCloudSDK.h>
2
+ #import <EXMarketingCloudSdk/EXMarketingCloudSdk.h>
3
+ #import <ExpoModulesCore/EXDefines.h>
4
+
5
+ @interface EXMarketingCloudSdk ()
6
+
7
+ @property (nonatomic, weak) EXModuleRegistry *moduleRegistry;
8
+
9
+ @end
10
+
11
+ @implementation EXMarketingCloudSdk
12
+
13
+ EX_REGISTER_SINGLETON_MODULE(MarketingCloud);
14
+
15
+ # pragma mark - EXModuleRegistryConsumer
16
+
17
+ - (void)setModuleRegistry:(EXModuleRegistry *)moduleRegistry
18
+ {
19
+ _moduleRegistry = moduleRegistry;
20
+ }
21
+
22
+ # pragma mark - UIApplicationDelegate
23
+
24
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions
25
+ {
26
+ NSString *sfmcApplicationId = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SFMCApplicationId"];
27
+ NSString *sfmcAccessToken = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SFMCAccessToken"];
28
+ NSNumber *sfmcAnalyticsEnabled = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SFMCAnalyticsEnabled"];
29
+ NSString *sfmcServerUrl = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SFMCServerUrl"];
30
+
31
+ MarketingCloudSDKConfigBuilder *mcsdkBuilder = [MarketingCloudSDKConfigBuilder new];
32
+ [mcsdkBuilder sfmc_setApplicationId:sfmcApplicationId];
33
+ [mcsdkBuilder sfmc_setAccessToken:sfmcAccessToken];
34
+ [mcsdkBuilder sfmc_setAnalyticsEnabled:sfmcAnalyticsEnabled];
35
+ [mcsdkBuilder sfmc_setMarketingCloudServerUrl:sfmcServerUrl];
36
+
37
+ NSError *error = nil;
38
+ BOOL success = [[MarketingCloudSDK sharedInstance] sfmc_configureWithDictionary:[mcsdkBuilder sfmc_build] error:&error];
39
+
40
+ if (success == YES) {
41
+ dispatch_async(dispatch_get_main_queue(), ^{
42
+ // set the UNUserNotificationCenter delegate - the delegate must be set here in
43
+ // didFinishLaunchingWithOptions
44
+ [UNUserNotificationCenter currentNotificationCenter].delegate = self;
45
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
46
+
47
+ [[UNUserNotificationCenter currentNotificationCenter]
48
+ requestAuthorizationWithOptions:UNAuthorizationOptionAlert |
49
+ UNAuthorizationOptionSound |
50
+ UNAuthorizationOptionBadge
51
+ completionHandler:^(BOOL granted, NSError *_Nullable error) {
52
+ if (error == nil) {
53
+ if (granted == YES) {
54
+ dispatch_async(dispatch_get_main_queue(), ^{
55
+ });
56
+ }
57
+ }
58
+ }];
59
+ });
60
+ } else {
61
+ // MarketingCloudSDK sfmc_configure failed
62
+ os_log_debug(OS_LOG_DEFAULT, "MarketingCloudSDK sfmc_configure failed with error = %@",
63
+ error);
64
+ }
65
+ return YES;
66
+ }
67
+
68
+ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
69
+ {
70
+ // This method is REQUIRED for correct functionality of the SDK.
71
+ // This method will be called on the delegate when the application receives a silent push
72
+ [[MarketingCloudSDK sharedInstance] sfmc_setNotificationUserInfo:userInfo];
73
+ completionHandler(UIBackgroundFetchResultNewData);
74
+ }
75
+
76
+ # pragma mark - UNUserNotificationCenterDelegate
77
+
78
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
79
+ {
80
+ NSLog(@"User Info : %@", notification.request.content.userInfo);
81
+ completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
82
+ }
83
+
84
+ // The method will be called on the delegate when the user responded to the notification by opening
85
+ // the application, dismissing the notification or choosing a UNNotificationAction. The delegate
86
+ // must be set before the application returns from applicationDidFinishLaunching:.
87
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
88
+ {
89
+ // tell the MarketingCloudSDK about the notification
90
+ [[MarketingCloudSDK sharedInstance] sfmc_setNotificationRequest:response.notification.request];
91
+
92
+ if (completionHandler != nil) {
93
+ completionHandler();
94
+ }
95
+ }
96
+
97
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification
98
+ {
99
+ }
100
+
101
+ @end
@@ -0,0 +1,26 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'EXMarketingCloudSdk'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.description = package['description']
10
+ s.license = package['license']
11
+ s.author = package['author']
12
+ s.homepage = package['homepage']
13
+ s.platform = :ios, '12.0'
14
+ s.source = { git: 'https://github.com/allboatsrise/expo-marketingcloudsdk.git' }
15
+ s.static_framework = true
16
+
17
+ s.dependency 'ExpoModulesCore'
18
+ s.dependency 'RNMarketingCloudSdk', '~>7.5.1'
19
+
20
+ if !$ExpoUseSources&.include?(package['name']) && ENV['EXPO_USE_SOURCE'].to_i == 0 && File.exist?("#{s.name}.xcframework") && Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.10.0')
21
+ s.source_files = "#{s.name}/**/*.h"
22
+ s.vendored_frameworks = "#{s.name}.xcframework"
23
+ else
24
+ s.source_files = "#{s.name}/**/*.{h,m}"
25
+ end
26
+ end
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@allboatsrise/expo-marketingcloudsdk",
3
3
  "author": "All Boats Rise Inc.",
4
4
  "license": "MIT",
5
- "version": "45.0.0",
5
+ "version": "46.0.0",
6
6
  "description": "Expo module for Salesforce Marketing Cloud SDK",
7
7
  "homepage": "https://github.com/allboatsrise/expo-marketingcloudsdk",
8
8
  "keywords": [
@@ -24,10 +24,12 @@
24
24
  "sideEffects": false,
25
25
  "files": [
26
26
  "/build/**/*",
27
+ "/ios/**/*",
27
28
  "/plugin/build/**/*",
28
29
  "/app.plugin.js",
29
30
  "/package.json",
30
- "/README.md"
31
+ "/README.md",
32
+ "/unimodule.json"
31
33
  ],
32
34
  "scripts": {
33
35
  "build": "expo-module build",
@@ -42,15 +44,15 @@
42
44
  "preset": "expo-module-scripts"
43
45
  },
44
46
  "dependencies": {
45
- "@expo/config-plugins": "^4.0.0"
47
+ "@expo/config-plugins": "^5.0.0"
46
48
  },
47
49
  "devDependencies": {
48
50
  "expo-module-scripts": "^2.0.0",
49
- "react-native-marketingcloudsdk": "^7.4.3"
51
+ "react-native-marketingcloudsdk": "^7.5.1"
50
52
  },
51
53
  "peerDependencies": {
52
- "@expo/config-plugins": "^4.0.0",
54
+ "@expo/config-plugins": "^5.0.0",
53
55
  "expo": "*",
54
- "react-native-marketingcloudsdk": "^7.4.3"
56
+ "react-native-marketingcloudsdk": "^7.5.1"
55
57
  }
56
58
  }
@@ -1,20 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.withIOSConfig = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
4
  const config_plugins_1 = require("@expo/config-plugins");
10
- const Xcodeproj_1 = require("@expo/config-plugins/build/ios/utils/Xcodeproj");
11
- const generateCode_1 = require("@expo/config-plugins/build/utils/generateCode");
12
5
  const withIOSConfig = (config, props) => {
13
6
  config = withEntitlements(config, props);
14
- config = withExtraAppDelegateProtocols(config, props);
15
- config = withConfiguration(config, props);
16
- config = withPushConfiguration(config, props);
17
- config = withDelegateImplementation(config, props);
7
+ config = withInfo(config, props);
18
8
  return config;
19
9
  };
20
10
  exports.withIOSConfig = withIOSConfig;
@@ -24,159 +14,13 @@ const withEntitlements = (config, { mode = 'development' }) => {
24
14
  return config;
25
15
  });
26
16
  };
27
- const withExtraAppDelegateProtocols = (config) => {
28
- return (0, config_plugins_1.withDangerousMod)(config, [
29
- 'ios',
30
- async (config) => {
31
- const appDelegateHeaderFile = path_1.default.join(config.modRequest.platformProjectRoot, (0, Xcodeproj_1.getProjectName)(config.modRequest.projectRoot), 'AppDelegate.h');
32
- let headerContent = fs_1.default.readFileSync(appDelegateHeaderFile, 'utf8');
33
- ['UIApplicationDelegate', 'UNUserNotificationCenterDelegate'].forEach(protocol => {
34
- if (headerContent.match(new RegExp(`${protocol}`)))
35
- return config;
36
- headerContent = headerContent.replace(/(EXAppDelegateWrapper\s*<.*?RCTBridgeDelegate.*?)(>)/, `$1, ${protocol}$2`);
37
- });
38
- fs_1.default.writeFileSync(appDelegateHeaderFile, headerContent);
39
- return config;
40
- }
41
- ]);
42
- };
43
- const withConfiguration = (config, props) => {
44
- return (0, config_plugins_1.withAppDelegate)(config, async (config) => {
45
- config.modResults.contents = (0, generateCode_1.mergeContents)({
46
- src: config.modResults.contents,
47
- newSrc: `#import <MarketingCloudSDK/MarketingCloudSDK.h>`,
48
- anchor: /#import "AppDelegate\.h"/,
49
- offset: 1,
50
- tag: '@allboatsrise/expo-marketingcloudsdk(header)',
51
- comment: '//'
52
- }).contents;
53
- config.modResults.contents = (0, generateCode_1.mergeContents)({
54
- src: config.modResults.contents,
55
- newSrc: ` MarketingCloudSDKConfigBuilder *mcsdkBuilder = [MarketingCloudSDKConfigBuilder new];
56
- [mcsdkBuilder sfmc_setApplicationId:@${JSON.stringify(props.appId)}];
57
- [mcsdkBuilder sfmc_setAccessToken:@${JSON.stringify(props.accessToken)}];
58
- [mcsdkBuilder sfmc_setAnalyticsEnabled:@(${props.analyticsEnabled ? 'YES' : 'NO'})];
59
- [mcsdkBuilder sfmc_setMarketingCloudServerUrl:@${JSON.stringify(props.serverUrl)}];
60
-
61
- NSError *error = nil;
62
- BOOL success = [[MarketingCloudSDK sharedInstance] sfmc_configureWithDictionary:[mcsdkBuilder sfmc_build] error:&error];`,
63
- anchor: /\[super application:application didFinishLaunchingWithOptions:launchOptions\];/,
64
- offset: -1,
65
- tag: '@allboatsrise/expo-marketingcloudsdk(configuration)',
66
- comment: '//'
67
- }).contents;
68
- return config;
69
- });
70
- };
71
- const withPushConfiguration = (config, props) => {
72
- return (0, config_plugins_1.withAppDelegate)(config, async (config) => {
73
- config.modResults.contents = (0, generateCode_1.mergeContents)({
74
- src: config.modResults.contents,
75
- newSrc: ` if (success == YES) {
76
- dispatch_async(dispatch_get_main_queue(), ^{
77
- if (@available(iOS 10, *)) {
78
- // set the UNUserNotificationCenter delegate - the delegate must be set here in
79
- // didFinishLaunchingWithOptions
80
- [UNUserNotificationCenter currentNotificationCenter].delegate = self;
81
- [[UIApplication sharedApplication] registerForRemoteNotifications];
82
-
83
- [[UNUserNotificationCenter currentNotificationCenter]
84
- requestAuthorizationWithOptions:UNAuthorizationOptionAlert |
85
- UNAuthorizationOptionSound |
86
- UNAuthorizationOptionBadge
87
- completionHandler:^(BOOL granted, NSError *_Nullable error) {
88
- if (error == nil) {
89
- if (granted == YES) {
90
- dispatch_async(dispatch_get_main_queue(), ^{
91
- });
92
- }
93
- }
94
- }];
95
- } else {
96
- #if __IPHONE_OS_VERSION_MIN_REQUIRED < 100000
97
- UIUserNotificationSettings *settings = [UIUserNotificationSettings
98
- settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound |
99
- UIUserNotificationTypeAlert
100
- categories:nil];
101
- [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
102
- #endif
103
- [[UIApplication sharedApplication] registerForRemoteNotifications];
104
- }
105
- });
106
- } else {
107
- // MarketingCloudSDK sfmc_configure failed
108
- os_log_debug(OS_LOG_DEFAULT, "MarketingCloudSDK sfmc_configure failed with error = %@",
109
- error);
110
- }`,
111
- anchor: /\[super application:application didFinishLaunchingWithOptions:launchOptions\];/,
112
- offset: 1,
113
- tag: '@allboatsrise/expo-marketingcloudsdk(push-configuration)',
114
- comment: '//'
115
- }).contents;
116
- return config;
117
- });
118
- };
119
- const withDelegateImplementation = (config, props) => {
120
- return (0, config_plugins_1.withAppDelegate)(config, async (config) => {
121
- config.modResults.contents = (0, generateCode_1.mergeContents)({
122
- src: config.modResults.contents,
123
- newSrc: ` [[MarketingCloudSDK sharedInstance] sfmc_setDeviceToken:deviceToken];`,
124
- anchor: /return \[super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken\];/,
125
- offset: 0,
126
- tag: '@allboatsrise/expo-marketingcloudsdk(user-notification-method-didRegisterForRemoteNotificationsWithDeviceToken)',
127
- comment: '//'
128
- }).contents;
129
- config.modResults.contents = (0, generateCode_1.mergeContents)({
130
- src: config.modResults.contents,
131
- newSrc: `os_log_debug(OS_LOG_DEFAULT, "didFailToRegisterForRemoteNotificationsWithError = %@", error);`,
132
- anchor: /return \[super application:application didFailToRegisterForRemoteNotificationsWithError:error\];/,
133
- offset: 0,
134
- tag: '@allboatsrise/expo-marketingcloudsdk(user-notification-method-didFailToRegisterForRemoteNotificationsWithError)',
135
- comment: '//'
136
- }).contents;
137
- config.modResults.contents = (0, generateCode_1.mergeContents)({
138
- src: config.modResults.contents,
139
- newSrc: `
140
- // The method will be called on the delegate when the user responded to the notification by opening
141
- // the application, dismissing the notification or choosing a UNNotificationAction. The delegate
142
- // must be set before the application returns from applicationDidFinishLaunching:.
143
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center
144
- didReceiveNotificationResponse:(UNNotificationResponse *)response
145
- withCompletionHandler:(void (^)(void))completionHandler {
146
- // tell the MarketingCloudSDK about the notification
147
- [[MarketingCloudSDK sharedInstance] sfmc_setNotificationRequest:response.notification.request];
148
-
149
- if (completionHandler != nil) {
150
- completionHandler();
151
- }
152
- }
153
-
154
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center
155
- willPresentNotification:(UNNotification *)notification
156
- withCompletionHandler:
157
- (void (^)(UNNotificationPresentationOptions options))completionHandler {
158
- NSLog(@"User Info : %@", notification.request.content.userInfo);
159
- completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert |
160
- UNAuthorizationOptionBadge);
161
- }`.trim(),
162
- anchor: /-\s*\(BOOL\)application:\(UIApplication\s*\*\)application\s*didFinishLaunchingWithOptions/,
163
- offset: -1,
164
- tag: '@allboatsrise/expo-marketingcloudsdk(user-notification-methods)',
165
- comment: '//'
166
- }).contents;
167
- config.modResults.contents = (0, generateCode_1.mergeContents)({
168
- src: config.modResults.contents,
169
- newSrc: `
170
- // This method is REQUIRED for correct functionality of the SDK.
171
- // This method will be called on the delegate when the application receives a silent push
172
- [[MarketingCloudSDK sharedInstance] sfmc_setNotificationUserInfo:userInfo];
173
- completionHandler(UIBackgroundFetchResultNewData);
174
- `,
175
- anchor: /return \[super application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler\]/,
176
- offset: 0,
177
- tag: '@allboatsrise/expo-marketingcloudsdk(user-notification-method-didReceiveRemoteNotification)',
178
- comment: '//'
179
- }).contents;
17
+ const withInfo = (config, props) => {
18
+ return (0, config_plugins_1.withInfoPlist)(config, (config) => {
19
+ var _a;
20
+ config.modResults.SFMCApplicationId = props.appId;
21
+ config.modResults.SFMCAccessToken = props.accessToken;
22
+ config.modResults.SFMCAnalyticsEnabled = (_a = props.analyticsEnabled) !== null && _a !== void 0 ? _a : false;
23
+ config.modResults.SFMCServerUrl = props.serverUrl;
180
24
  return config;
181
25
  });
182
26
  };
package/unimodule.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "expo-marketingcloudsdk",
3
+ "platforms": ["ios"]
4
+ }