@allboatsrise/expo-marketingcloudsdk 46.0.1 → 46.2.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.
@@ -1,19 +1,14 @@
1
1
  #import <Foundation/Foundation.h>
2
2
  #import <UIKit/UIKit.h>
3
- #import <UserNotifications/UserNotifications.h>
4
3
  #import <ExpoModulesCore/EXSingletonModule.h>
5
4
  #import <ExpoModulesCore/EXModuleRegistryConsumer.h>
5
+ #import <EXNotifications/EXNotificationsDelegate.h>
6
6
 
7
7
  NS_ASSUME_NONNULL_BEGIN
8
8
 
9
- @interface EXMarketingCloudSdk : EXSingletonModule <UIApplicationDelegate, UNUserNotificationCenterDelegate, EXModuleRegistryConsumer>
9
+ @interface EXMarketingCloudSdk : EXSingletonModule <UIApplicationDelegate, EXModuleRegistryConsumer, EXNotificationsDelegate>
10
10
 
11
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
12
 
18
13
  @end
19
14
 
@@ -1,10 +1,11 @@
1
1
  #import <MarketingCloudSDK/MarketingCloudSDK.h>
2
2
  #import <EXMarketingCloudSdk/EXMarketingCloudSdk.h>
3
3
  #import <ExpoModulesCore/EXDefines.h>
4
+ #import <EXNotifications/EXNotificationCenterDelegate.h>
4
5
 
5
6
  @interface EXMarketingCloudSdk ()
6
7
 
7
- @property (nonatomic, weak) EXModuleRegistry *moduleRegistry;
8
+ @property (nonatomic, weak) id<EXNotificationCenterDelegate> notificationCenterDelegate;
8
9
 
9
10
  @end
10
11
 
@@ -16,86 +17,55 @@ EX_REGISTER_SINGLETON_MODULE(MarketingCloud);
16
17
 
17
18
  - (void)setModuleRegistry:(EXModuleRegistry *)moduleRegistry
18
19
  {
19
- _moduleRegistry = moduleRegistry;
20
+ _notificationCenterDelegate = [moduleRegistry getSingletonModuleForName:@"NotificationCenterDelegate"];
20
21
  }
21
22
 
22
23
  # pragma mark - UIApplicationDelegate
23
24
 
24
25
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions
25
26
  {
26
- NSString *sfmcApplicationId = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SFMCApplicationId"];
27
27
  NSString *sfmcAccessToken = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SFMCAccessToken"];
28
28
  NSNumber *sfmcAnalyticsEnabled = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SFMCAnalyticsEnabled"];
29
+ NSString *sfmcAppId = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SFMCApplicationId"];
30
+ NSNumber *sfmcAppControlsBadging = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SFMCApplicationControlsBadging"];
31
+ NSNumber *sfmcDelayRegistrationUntilContactKeyIsSet = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SFMCDelayRegistrationUntilContactKeyIsSet"];
32
+ NSNumber *sfmcInboxEnabled = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SFMCInboxEnabled"];
33
+ NSNumber *sfmcLocationEnabled = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SFMCLocationEnabled"];
34
+ NSString *sfmcMid = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SFMCMid"];
29
35
  NSString *sfmcServerUrl = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SFMCServerUrl"];
30
36
 
31
37
  MarketingCloudSDKConfigBuilder *mcsdkBuilder = [MarketingCloudSDKConfigBuilder new];
32
- [mcsdkBuilder sfmc_setApplicationId:sfmcApplicationId];
33
38
  [mcsdkBuilder sfmc_setAccessToken:sfmcAccessToken];
34
39
  [mcsdkBuilder sfmc_setAnalyticsEnabled:sfmcAnalyticsEnabled];
40
+ [mcsdkBuilder sfmc_setApplicationId:sfmcAppId];
41
+ [mcsdkBuilder sfmc_setApplicationControlsBadging:sfmcAppControlsBadging];
42
+ [mcsdkBuilder sfmc_setDelayRegistrationUntilContactKeyIsSet:sfmcDelayRegistrationUntilContactKeyIsSet];
43
+ [mcsdkBuilder sfmc_setInboxEnabled:sfmcInboxEnabled];
44
+ [mcsdkBuilder sfmc_setLocationEnabled:sfmcLocationEnabled];
45
+ if ([sfmcMid length] > 0) [mcsdkBuilder sfmc_setMid:sfmcMid];
35
46
  [mcsdkBuilder sfmc_setMarketingCloudServerUrl:sfmcServerUrl];
36
47
 
37
48
  NSError *error = nil;
38
49
  BOOL success = [[MarketingCloudSDK sharedInstance] sfmc_configureWithDictionary:[mcsdkBuilder sfmc_build] error:&error];
39
50
 
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
- }
51
+ if (success != YES) {
52
+ EXLogError(@"[expo-marketingcloudsdk] Failed to initialize instance. (error: %@)", error);
53
+ } else {
54
+ [_notificationCenterDelegate addDelegate:self];
55
+ }
56
+
65
57
  return YES;
66
58
  }
67
59
 
60
+ //# pragma mark - EXNotificationsDelegate
61
+
62
+ // MobilePush SDK: REQUIRED IMPLEMENTATION
63
+ /** This delegate method offers an opportunity for applications with the "remote-notification" background mode to fetch appropriate new data in response to an incoming remote notification. You should call the fetchCompletionHandler as soon as you're finished performing that operation, so the system can accurately estimate its power and data cost.
64
+ This method will be invoked even if the application was launched or resumed because of the remote notification. The respective delegate methods will be invoked first. Note that this behavior is in contrast to application:didReceiveRemoteNotification:, which is not called in those cases, and which will not be invoked if this method is implemented. **/
68
65
  - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
69
66
  {
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
67
  [[MarketingCloudSDK sharedInstance] sfmc_setNotificationUserInfo:userInfo];
73
68
  completionHandler(UIBackgroundFetchResultNewData);
74
69
  }
75
70
 
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
71
  @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": "46.0.1",
5
+ "version": "46.2.0",
6
6
  "description": "Expo module for Salesforce Marketing Cloud SDK",
7
7
  "homepage": "https://github.com/allboatsrise/expo-marketingcloudsdk",
8
8
  "keywords": [
@@ -53,6 +53,7 @@
53
53
  "peerDependencies": {
54
54
  "@expo/config-plugins": "^5.0.0",
55
55
  "expo": "*",
56
+ "expo-notifications": "^0.16.1",
56
57
  "react-native-marketingcloudsdk": "^7.5.1"
57
58
  }
58
59
  }
@@ -3,24 +3,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withIOSConfig = void 0;
4
4
  const config_plugins_1 = require("@expo/config-plugins");
5
5
  const withIOSConfig = (config, props) => {
6
- config = withEntitlements(config, props);
7
6
  config = withInfo(config, props);
7
+ config = withRemoteNotificationsBackgroundMode(config, props);
8
8
  return config;
9
9
  };
10
10
  exports.withIOSConfig = withIOSConfig;
11
- const withEntitlements = (config, { mode = 'development' }) => {
12
- return (0, config_plugins_1.withEntitlementsPlist)(config, async (config) => {
13
- config.modResults['aps-environment'] = mode;
14
- return config;
15
- });
16
- };
17
11
  const withInfo = (config, props) => {
18
12
  return (0, config_plugins_1.withInfoPlist)(config, (config) => {
19
- var _a;
20
- config.modResults.SFMCApplicationId = props.appId;
13
+ var _a, _b, _c, _d, _e, _f;
21
14
  config.modResults.SFMCAccessToken = props.accessToken;
22
15
  config.modResults.SFMCAnalyticsEnabled = (_a = props.analyticsEnabled) !== null && _a !== void 0 ? _a : false;
16
+ config.modResults.SFMCApplicationId = props.appId;
17
+ config.modResults.SFMCApplicationControlsBadging = (_b = props.applicationControlsBadging) !== null && _b !== void 0 ? _b : false;
18
+ config.modResults.SFMCDelayRegistrationUntilContactKeyIsSet = (_c = props.delayRegistrationUntilContactKeyIsSet) !== null && _c !== void 0 ? _c : false;
19
+ config.modResults.SFMCInboxEnabled = (_d = props.inboxEnabled) !== null && _d !== void 0 ? _d : false;
20
+ config.modResults.SFMCLocationEnabled = (_e = props.locationEnabled) !== null && _e !== void 0 ? _e : false;
21
+ config.modResults.SFMCMid = (_f = props.mid) !== null && _f !== void 0 ? _f : '';
23
22
  config.modResults.SFMCServerUrl = props.serverUrl;
24
23
  return config;
25
24
  });
26
25
  };
26
+ const withRemoteNotificationsBackgroundMode = (config, props) => {
27
+ config = (0, config_plugins_1.withInfoPlist)(config, (config) => {
28
+ if (!Array.isArray(config.modResults.UIBackgroundModes)) {
29
+ config.modResults.UIBackgroundModes = [];
30
+ }
31
+ if (!config.modResults.UIBackgroundModes.includes('remote-notification')) {
32
+ config.modResults.UIBackgroundModes.push('remote-notification');
33
+ }
34
+ return config;
35
+ });
36
+ return config;
37
+ };
@@ -16,10 +16,28 @@ export declare type MarketingCloudSdkPluginProps = {
16
16
  * defined in `android.googleServicesFile` (google-services.json) if defined.
17
17
  */
18
18
  senderId?: string;
19
+ /**
20
+ * Sets the configuration value to use for the Salesforce MarketingCloud Tenant Specific mid.
21
+ */
22
+ mid?: string;
23
+ /**
24
+ * Sets the configuration flag that enables or disables inbox services
25
+ */
26
+ inboxEnabled?: boolean;
27
+ /**
28
+ * Sets the configuration flag that enables or disables location services
29
+ */
30
+ locationEnabled?: boolean;
31
+ /**
32
+ * Sets the configuration flag that enables or disables Salesforce MarketingCloud Analytics services
33
+ */
19
34
  analyticsEnabled?: boolean;
20
35
  /**
21
- * (iOS only) Environment of the app: either 'development' or 'production'. Defaults to 'development'.
22
- * @default 'development'
36
+ * Sets the configuration value which enables or disables application control over badging
37
+ */
38
+ applicationControlsBadging?: boolean;
39
+ /**
40
+ * Sets the configuration value which enables or disables application control over delaying SDK registration until a contact key is set
23
41
  */
24
- mode?: 'development' | 'production';
42
+ delayRegistrationUntilContactKeyIsSet?: boolean;
25
43
  };