From efd4e82ee4d01ef5554ec406a3536ae14c35d72d Mon Sep 17 00:00:00 2001 From: Neerhaj N Joshi Date: Mon, 28 Mar 2022 07:36:22 +0530 Subject: [PATCH] Release v6.52.0 --- .gitignore | 2 - README.md | 4 +- android/android.iml | 134 -------- android/build.gradle | 3 - .../pushio/manager/rn/RCTPushIOManager.java | 58 ++++ iOS.Example.md | 318 ++++++++++++++++++ index.js | 24 ++ ios/RCTPushIOEventEmitter.m | 13 +- ios/RCTPushIOManager.m | 18 + package.json | 2 +- 10 files changed, 433 insertions(+), 143 deletions(-) delete mode 100644 android/android.iml create mode 100644 iOS.Example.md diff --git a/.gitignore b/.gitignore index 780b82b..e0ec21f 100644 --- a/.gitignore +++ b/.gitignore @@ -45,5 +45,3 @@ yarn.lock android/.classpath/ android/.project/ android/.settings/ -android/.classpath -android/.project \ No newline at end of file diff --git a/README.md b/README.md index e1e3459..c9f4171 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Before installing the plugin, you must setup your app to receive push notificati - [Generate Auth Key](https://docs.oracle.com/en/cloud/saas/marketing/responsys-develop-mobile/ios/auth-key/) - Log in to the [Responsys Mobile App Developer Console](https://docs.oracle.com/en/cloud/saas/marketing/responsys-develop-mobile/dev-console/login/) and enter your Auth Key and other details for your iOS app. - Download the `pushio_config.json` file generated from your credentials. -- ***Important:*** Copy `PushIOManager.framework` and place it in the plugin `YOUR_APP_DIR/ios/framework/` folder **before adding plugin to project**. +- ***Important:*** Copy `PushIOManager.framework` and place it in `YOUR_APP_DIR/ios/framework/` folder **before adding plugin to project**. ## Installation @@ -73,7 +73,7 @@ yarn add @oracle/react-native-pushiomanager ```gradle configurations.maybeCreate("default") - artifacts.add("default", file('PushIOManager-6.51.aar')) + artifacts.add("default", file('PushIOManager-6.52.aar')) ``` - Add the following to your project-wide `settings.gradle` file: diff --git a/android/android.iml b/android/android.iml deleted file mode 100644 index 646bfe1..0000000 --- a/android/android.iml +++ /dev/null @@ -1,134 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index 59ba974..2518d7d 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -38,9 +38,6 @@ buildscript { } } -apply plugin: 'com.android.library' -apply plugin: 'maven' - android { compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION) diff --git a/android/src/main/java/com/pushio/manager/rn/RCTPushIOManager.java b/android/src/main/java/com/pushio/manager/rn/RCTPushIOManager.java index 620e517..fa457f9 100644 --- a/android/src/main/java/com/pushio/manager/rn/RCTPushIOManager.java +++ b/android/src/main/java/com/pushio/manager/rn/RCTPushIOManager.java @@ -26,6 +26,7 @@ import com.pushio.manager.PIOMCMessageError; import com.pushio.manager.PIOMCMessageListener; import com.pushio.manager.PIOMCRichContentListener; +import com.pushio.manager.PIOMessageCenterUpdateListener; import com.pushio.manager.PIORegionCompletionListener; import com.pushio.manager.PIORegionEventType; import com.pushio.manager.PIORegionException; @@ -894,6 +895,15 @@ private void emitEvent(String eventName, WritableMap map) { } } + private void emitEvent(String eventName, WritableArray array) { + try { + getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) + .emit(eventName, array); + } catch (Exception e) { + PIOLogger.v("RN eE " + e); + } + } + @ReactMethod public void setNotificationSmallIconColor(String colorHex) { if (!TextUtils.isEmpty(colorHex)) { @@ -903,6 +913,24 @@ public void setNotificationSmallIconColor(String colorHex) { } + @ReactMethod + public void setInAppMessageBannerHeight(int heightDP, final Callback callback) { + final boolean isBannerHeightSet = mPushIOManager.setInAppMessageBannerHeight(heightDP); + + if (callback != null) { + callback.invoke(null, isBannerHeightSet); + } + } + + @ReactMethod + public void getInAppMessageBannerHeight(final Callback callback) { + final int bannerHeight = mPushIOManager.getInAppMessageBannerHeight(); + + if (callback != null) { + callback.invoke(null, bannerHeight); + } + } + @ReactMethod public void setNotificationSmallIcon(String resourceName) { if (!TextUtils.isEmpty(resourceName)) { @@ -939,4 +967,34 @@ public void setNotificationLargeIcon(String resourceName) { } } + @ReactMethod + public void setStatusBarHiddenForIAMBannerInterstitial(boolean hideStatusBar) { + mPushIOManager.setStatusBarHiddenForIAMBannerInterstitial(hideStatusBar); + } + + @ReactMethod + public void isStatusBarHiddenForIAMBannerInterstitial(final Callback callback) { + final boolean isStatusBarHidden = mPushIOManager.isStatusBarHiddenForIAMBannerInterstitial(); + + if (callback != null) { + callback.invoke(null, isStatusBarHidden); + } + } + + @ReactMethod + public void addMessageCenterUpdateListener(boolean executeRsysWebUrl) { + + mPushIOManager.addMessageCenterUpdateListener(new PIOMessageCenterUpdateListener() { + @Override + public void onUpdate(List messageCenters) { + WritableArray writableMessageCenters = new WritableNativeArray(); + + for (String messageCenter : messageCenters) { + writableMessageCenters.pushString(messageCenter); + } + + emitEvent("PIOMessageCenterUpdateNotification", writableMessageCenters); + } + }); + } } diff --git a/iOS.Example.md b/iOS.Example.md new file mode 100644 index 0000000..887f381 --- /dev/null +++ b/iOS.Example.md @@ -0,0 +1,318 @@ +# Example React Native iOS Implementation for Responsys SDK + +This is the example implementation for iOS of PushIOManager SDK with React Native. + +## Requirements + +- PushIOManager.frameowk - [download latest SDK from here](https://www.oracle.com/downloads/applications/cx/responsys-mobile-sdk.html) +- pushio_config.json or pushio_debug_config.json - download from the Mobile Developer Console. Follow [Step 1 of this guide](https://docs.oracle.com/en/cloud/saas/marketing/responsys-develop-mobile/ios/step-by-step.htm). + + + +## 1. Install PushIOManager React Native module +Create new react app or go to existing app. +``` +cd +// Install the pushiomanager react native module +yarn add @oracle/react-native-pushiomanager // or npm install @oracle/react-native-pushiomanager +``` + +## 2. Setup PushIOManager framework installation +Run the below commands after installing the react-native-pushiomanager module + +``` +//Create Framework directory +mkdir ios/framework + +//Copy the podspec file in the framework directory. **This step is crucial** +cp node_modules/@oracle/react-native-pushiomanager/PushIOManager/PushIOManager.podspec ios/framework/ +``` + +Place the [latest iOS `PushIOManager.framework`](https://www.oracle.com/downloads/applications/cx/responsys-mobile-sdk.html) inside `ios/framework` + +After above these steps your framework directory should look like this. + +![FrameworkCopy](./img/framework_copy.png "Framework Copy") + + +## 3. Add PushIOManager dependency to Podfile + +Go to iOS directory in your react native app. Open the `Podfile` + +``` +use_native_modules! +pod 'PushIOManager', :path => './framework/' +``` + + +Sample Podfile after adding PushIOManager dependenct look like this. + +**Note:** This depends on the your react native version. Verify the PushIOManager setup. + +
+
+require_relative '../node_modules/react-native/scripts/react_native_pods'
+require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
+
+platform :ios, '11.0'
+
+target 'testapp' do
+  config = use_native_modules!
+
+  use_react_native!(
+    :path => config[:reactNativePath],
+    # to enable hermes on iOS, change `false` to `true` and then install pods
+    :hermes_enabled => false
+  )
+
+  target 'testappTests' do
+    inherit! :complete
+    # Pods for testing
+  end
+
+  # Enables Flipper.
+  #
+  # Note that if you have use_frameworks! enabled, Flipper will not work and
+  # you should disable the next line.
+  use_flipper!()
+  
+  use_native_modules!
+  pod 'PushIOManager', :path => './framework/'
+
+  post_install do |installer|
+    react_native_post_install(installer)
+    __apply_Xcode_12_5_M1_post_install_workaround(installer)
+  end
+end
+
+
+ +## 4. Install Pods +``` +//iOS directory in your react native app +cd ios +pod install +``` + +## 5. Copy pushio.config.json + +Download your **iOS** `pushio_config.json` from [Responsys Mobile App Developer Console](https://docs.oracle.com/en/cloud/saas/marketing/responsys-develop-mobile/dev-console/login/). + +Open your iOS project `/ios/.xcworkspace` in Xcode. + +Drag and Drop the `pushio_config.json` in **Xcode** in your `` directory + +Please make sure to select **``** in "Add to Targets" and also "Copy items if needed". + +![AddTarget](./img/add_target.png "AddTarget Copy") + + +## 5. Implementing Delegate Methods: + +Please make sure to implement the **Bold** code parts in your `AppDelegate.m`. + + +
+
+//Appdelegate.m
+
+#import "AppDelegate.h"
+
+#import <React/RCTBridge.h>
+#import <React/RCTBundleURLProvider.h>
+#import <React/RCTRootView.h>
+
+#ifdef FB_SONARKIT_ENABLED
+#import <FlipperKit/FlipperClient.h>
+#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
+#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
+#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
+#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
+#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
+
+
+//Import Framework
+#import <PushIOManager/PushIOManager.h>
+//For UserNotifications support
+#import <UserNotifications/UserNotifications.h>
+
+//Implement UserNotifications delegate to receive the notification callbacks in iOS 10.
+@interface AppDelegate()<UNUserNotificationCenterDelegate>
+@end
+
+
+static void InitializeFlipper(UIApplication *application) {
+  FlipperClient *client = [FlipperClient sharedClient];
+  SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
+  [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
+  [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
+  [client addPlugin:[FlipperKitReactPlugin new]];
+  [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
+  [client start];
+}
+#endif
+
+@implementation AppDelegate
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+  
+  
+#ifdef FB_SONARKIT_ENABLED
+  InitializeFlipper(application);
+#endif
+
+  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
+  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
+                                                   moduleName:@"testapp"
+                                            initialProperties:nil];
+![#f03c15](https://placehold.it/15/f03c15/000000?text=+) `#f03c15`
+  if (@available(iOS 13.0, *)) {
+      rootView.backgroundColor = [UIColor systemBackgroundColor];
+  } else {
+      rootView.backgroundColor = [UIColor whiteColor];
+  }
+
+  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
+  UIViewController *rootViewController = [UIViewController new];
+  rootViewController.view = rootView;
+  self.window.rootViewController = rootViewController;
+  [self.window makeKeyAndVisible];
+  
+
+  // Responsys implementation 
+  [UNUserNotificationCenter currentNotificationCenter].delegate = self;
+  
+  //To recieve the notifications in App foreground
+  [PushIOManager sharedInstance].notificationPresentationOptions = UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound;
+
+  // Call the didFinishLaunching of SDK at end.
+  [[PushIOManager sharedInstance] didFinishLaunchingWithOptions:launchOptions];
+  
+  return YES;
+}
+
+- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
+{
+#if DEBUG
+  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
+#else
+  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
+#endif
+}
+
+
+- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
+  [[PushIOManager sharedInstance] didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
+}
+
+- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
+fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
+  [[PushIOManager sharedInstance] didReceiveRemoteNotification:userInfo fetchCompletionResult:UIBackgroundFetchResultNewData fetchCompletionHandler:completionHandler];
+}
+
+- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
+    [[PushIOManager sharedInstance] didFailToRegisterForRemoteNotificationsWithError:error];
+}
+
+- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
+   [[PushIOManager sharedInstance] openURL:url options:options];
+  return YES;
+}
+
+//iOS 10 or later
+- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {
+
+    [[PushIOManager sharedInstance] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
+}
+
+-(void) userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:
+(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
+    [[PushIOManager sharedInstance] userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
+}
+
+- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
+    [[PushIOManager sharedInstance] openURL:url options:options];
+   return YES;
+}
+
+
+@end
+
+
+ + + +### Usage + +The module can be accessed in JS code as follows, + +```javascript +import PushIOManager from 'react-native-pushiomanager'; +``` + + +### Configure And Register + +- Configure the SDK, + + ```javascript + PushIOManager.configure("your-pushio_config_name.json", (error, response) => { + + }); + ``` + +- Once the SDK is configured, register the app with Responsys, + + ```javascript + import { Platform } from 'react-native'; + + if (Platform.OS === 'android') { + PushIOManager.registerApp(true, (error, response) => { + }); + } else { + PushIOManager.registerForAllRemoteNotificationTypes((error, response) => { //This api will raise iOS push permission alert + PushIOManager.registerApp(false, (error, response) => { + }); + }); + } + ``` +- **Combination of above steps** + ```javascript + import { Platform } from 'react-native'; + + PushIOManager.configure("your-pushio_config_name.json", (error, response) => { // Configure the SDK with config provided + if (Platform.OS === 'android') { + PushIOManager.registerApp(true, (error, response) => { //Register for android + + }); + } else { + PushIOManager.registerForAllRemoteNotificationTypes((error, response) => { //This api will raise iOS push permission alert + PushIOManager.registerApp(false, (error, response) => { //Register for iOS. `useLocation` is not supported in iOS. + + }); + }); + } + + }); + +- Additional APIs (optional) + + iOS Only: + - You can delay registration while app is launching or coming to foreground by implementing below API. + ``` + // Implement before `registerForAllRemoteNotificationTypes` calls. + PushIOManager.setDelayRegistration(true); + ``` + + +## Support + +If you have access to My Oracle Support, please raise a request [here](http://support.oracle.com/), otherwise open an issue in this repository. + + +## License + +Copyright (c) 2020 Oracle and/or its affiliates and released under the Universal Permissive License (UPL), Version 1.0. + +Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. diff --git a/index.js b/index.js index 3f3b339..6ef8787 100644 --- a/index.js +++ b/index.js @@ -1132,6 +1132,30 @@ export default class PushIOManager { } } + static setInAppMessageBannerHeight(height, callback) { + if (typeof height != 'number') { + console.log("Banner height should be a Number type"); + return; + } + RCTPushIOManager.setInAppMessageBannerHeight(height, callback); + } + + static getInAppMessageBannerHeight(callback) { + RCTPushIOManager.getInAppMessageBannerHeight(callback); + } + + static setStatusBarHiddenForIAMBannerInterstitial(hideStatusBar) { + RCTPushIOManager.setStatusBarHiddenForIAMBannerInterstitial(hideStatusBar) + } + + static isStatusBarHiddenForIAMBannerInterstitial(callback) { + RCTPushIOManager.isStatusBarHiddenForIAMBannerInterstitial(callback); + } + + static addMessageCenterUpdateListener(callback) { + RCTPushIOEventEmitter.addListener('PIOMessageCenterUpdateNotification', callback); + } + static setNotificationSmallIcon(resourceName) { if (Platform.OS === 'android') { RCTPushIOManager.setNotificationSmallIcon(resourceName); diff --git a/ios/RCTPushIOEventEmitter.m b/ios/RCTPushIOEventEmitter.m index cd26368..8a53f24 100644 --- a/ios/RCTPushIOEventEmitter.m +++ b/ios/RCTPushIOEventEmitter.m @@ -19,6 +19,7 @@ -(void)startObserving { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resolvedURL:) name:PIORsysWebURLResolvedNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:@"PIOHandleOpenURL" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(registerForAllRemoteNotifications) name:@"registerForAllRemoteNotificationTypes" object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMessageCenterUpdate:) name:PIOMessageCenterUpdateNotification object:nil]; } @@ -42,6 +43,7 @@ -(void)stopObserving { [[NSNotificationCenter defaultCenter] removeObserver:self name:@"registerForAllRemoteNotificationTypes" object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:PIORsysWebURLResolvedNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PIOHandleOpenURL" object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:PIOMessageCenterUpdateNotification object:nil]; hasListeners = NO; } @@ -59,9 +61,18 @@ - (void)handleOpenURL:(NSNotification *)notification { } - (NSArray *)supportedEvents { - return @[PIORsysWebURLResolvedNotification, @"PIOHandleOpenURL", @"registerForAllRemoteNotificationTypes"]; + return @[PIORsysWebURLResolvedNotification, @"PIOHandleOpenURL", @"registerForAllRemoteNotificationTypes",PIOMessageCenterUpdateNotification]; } +- (void)handleMessageCenterUpdate:(NSNotification *)notification { + if (hasListeners) { + NSArray *messageCenters = (NSArray *)[notification object]; + NSString *messageCenter = [messageCenters componentsJoinedByString:@","]; + [self sendEventWithName:PIOMessageCenterUpdateNotification body:messageCenter]; + } +} + + @end diff --git a/ios/RCTPushIOManager.m b/ios/RCTPushIOManager.m index 492f03b..417a104 100644 --- a/ios/RCTPushIOManager.m +++ b/ios/RCTPushIOManager.m @@ -396,5 +396,23 @@ - (BOOL)handleOpenURL:(NSURL *)url { return true; } +RCT_EXPORT_METHOD(setInAppMessageBannerHeight:(CGFloat )height completionHandler:(RCTResponseSenderBlock)callback) { + BOOL hasBannerHeightSet = [[PushIOManager sharedInstance] setInAppMessageBannerHeight:height]; + if(callback != nil){ + callback(@[[NSNull null], @(hasBannerHeightSet)]); + } +} + +RCT_EXPORT_METHOD(getInAppMessageBannerHeight:(RCTResponseSenderBlock)callback) { + callback(@[[NSNull null], @([[PushIOManager sharedInstance] getInAppMessageBannerHeight])]); +} + +RCT_EXPORT_METHOD(setStatusBarHiddenForIAMBannerInterstitial:(BOOL)hideStatusBar){ + [[PushIOManager sharedInstance] setStatusBarHiddenForIAMBannerInterstitial:hideStatusBar]; +} + +RCT_EXPORT_METHOD(isStatusBarHiddenForIAMBannerInterstitial:(RCTResponseSenderBlock)callback) { + callback(@[[NSNull null], @([[PushIOManager sharedInstance] isStatusBarHiddenForIAMBannerInterstitial])]); +} @end diff --git a/package.json b/package.json index 1a3fdb1..54b9c3f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oracle/react-native-pushiomanager", - "version": "6.51.0", + "version": "6.52.0", "description": "React Native Module for Responsys Mobile SDK", "main": "index.js", "repository": {