Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 7.0.0 #42

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
Batch Cordova Plugin

## 7.0.0

**Plugin**
* Updated Batch to 2.1
* Batch requires to compile with SDK 35 (Android 15) (cordova-android@14).

**iOS**
* `BatchBridgeNotificationCenterDelegate` now defaults to showing foreground notifications.

**Profile**
- Added `setPhoneNumber` API to the `BatchProfileAttributeEditor` class. This requires to have a user identifier registered or to call the `identify` method beforehand.
- Added `setSMSMarketingSubscription` API to the `BatchProfileAttributeEditor` class.

**Push**
- Removed deprecated API `registerForRemoteNotifications`. Please use `requestNotificationAuthorization` to request permission when needed, and `requestToken` at each app launch.

## 6.0.0

This is a major release, please see our [migration guide](https://doc.batch.com/cordova/migrations/5x-migration/) for more info on how to update your current Batch implementation.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This repository contains the plugin's source code (native code + cordova) and bu
This plugin is compatible with:

- cordova 9.0.0+
- cordova-android 9.0.0+
- cordova-android 14.0.0+
- cordova-ios 6.0.0+

Subsequent major Cordova and Cordova platform versions are _not_ supported until told otherwise.
Expand Down
7 changes: 6 additions & 1 deletion dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@batch.com/cordova-plugin",
"version": "6.0.0",
"version": "7.0.0",
"description": "Batch.com SDK Cordova/Ionic plugin for Android and iOS",
"types": "index.d.ts",
"cordova": {
Expand Down Expand Up @@ -56,6 +56,11 @@
"cordova": ">=9.0.0",
"cordova-android": ">=9.0.0",
"cordova-ios": ">=6.0.0"
},
"7.0.0": {
"cordova": ">=9.0.0",
"cordova-android": ">=14.0.0",
"cordova-ios": ">=6.0.0"
}
},
"author": "Batch.com",
Expand Down
8 changes: 4 additions & 4 deletions dist/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="@batch.com/cordova-plugin"
version="6.0.0">
version="7.0.0">
<engines>
<engine name="cordova" version=">=9.0.0" />
<engine name="cordova-android" version=">=9.0.0" />
<engine name="cordova-android" version=">=14.0.0" />
<engine name="cordova-ios" version=">=6.0.0" />
</engines>
<name>Batch</name>
Expand All @@ -19,7 +19,7 @@

<platform name="android">

<preference name="BATCHSDK_ANDROID_VERSION" default="2.0.+"/>
<preference name="BATCHSDK_ANDROID_VERSION" default="2.1.+"/>

<!-- This should be 1.0.0 forever, we leave it configurable just in case another version needs to be used in an app -->
<preference name="BATCHSDK_ANDROID_LOCALBROADCAST_VERSION" default="1.0.0"/>
Expand Down Expand Up @@ -79,7 +79,7 @@

<platform name="ios">

<preference name="BATCHSDK_IOS_VERSION" default="~> 2.0"/>
<preference name="BATCHSDK_IOS_VERSION" default="~> 2.1"/>

<config-file target="config.xml" parent="/*">
<feature name="Batch">
Expand Down
2 changes: 1 addition & 1 deletion dist/src/android/BatchCordovaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class BatchCordovaPlugin extends CordovaPlugin implements Callback, Logge

private static final String PLUGIN_VERSION_ENVIRONEMENT_VAR = "batch.plugin.version";

private static final String PLUGIN_VERSION = "Cordova/6.0.0";
private static final String PLUGIN_VERSION = "Cordova/7.0.0";

/**
* Key used to add extra to an intent to prevent it to be used more than once to compute opens
Expand Down
1 change: 0 additions & 1 deletion dist/src/android/interop/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public enum Action
MESSAGING_SET_DO_NOT_DISTURB_ENABLED("messaging.setDoNotDisturbEnabled"),
MESSAGING_SHOW_PENDING_MESSAGE("messaging.showPendingMessage"),
PUSH_GET_LAST_KNOWN_TOKEN("push.getLastKnownPushToken"),
PUSH_REGISTER("push.register"),
PUSH_SET_GCM_SENDER_ID("push.setGCMSenderID"),
PUSH_CLEAR_BADGE("push.clearBadge"),
PUSH_DISMISS_NOTIFICATIONS("push.dismissNotifications"),
Expand Down
29 changes: 26 additions & 3 deletions dist/src/android/interop/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.batch.android.Batch;
import com.batch.android.BatchAttributesFetchListener;
import com.batch.android.BatchEmailSubscriptionState;
import com.batch.android.BatchSMSSubscriptionState;
import com.batch.android.BatchEventAttributes;
import com.batch.android.BatchMessage;
import com.batch.android.BatchMigration;
Expand Down Expand Up @@ -138,9 +139,6 @@ private static SimplePromise<String> doAction(String actionName, Map<String, Obj
case PUSH_DISMISS_NOTIFICATIONS:
dismissNotifications();
break;
case PUSH_REGISTER:
// iOS only, do nothing
return null;
case PUSH_CLEAR_BADGE:
// iOS only, do nothing
return null;
Expand Down Expand Up @@ -410,6 +408,31 @@ private static void editProfileAttributes(Map<String, Object> parameters) throws
Log.e(TAG, "Invalid SET_EMAIL_MARKETING_SUBSCRIPTION value: it can only be `subscribed` or `unsubscribed`.");
}
}
case "SET_PHONE_NUMBER" -> {
Object value = operationDescription.get("value");
if (value != null && !(value instanceof String)) {
Log.e(TAG, "Invalid SET_PHONE_NUMBER value: it can only be a string or null");
// Invalid value, continue. NULL is allowed though
continue;
}
editor.setPhoneNumber((String) value);
}
case "SET_SMS_MARKETING_SUB" -> {
Object value = operationDescription.get("value");
if (value == null || !(value instanceof String)) {
Log.e(TAG, "Invalid SET_SMS_MARKETING_SUB value: it can only be a string");
// Invalid value, continue.
continue;
}

if ("subscribed".equals(value)) {
editor.setSMSMarketingSubscription(BatchSMSSubscriptionState.SUBSCRIBED);
} else if ("unsubscribed".equals(value)) {
editor.setSMSMarketingSubscription(BatchSMSSubscriptionState.UNSUBSCRIBED);
} else {
Log.e(TAG, "Invalid SET_SMS_MARKETING_SUB value: it can only be `subscribed` or `unsubscribed`.");
}
}
case "SET_ATTRIBUTE" -> {
String key = getTypedParameter(operationDescription, "key", String.class);
String type = getTypedParameter(operationDescription, "type", String.class);
Expand Down
2 changes: 1 addition & 1 deletion dist/src/ios/BatchCordovaPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import "BatchBridge.h"
#import "BatchBridgeCallback.h"

#define PluginVersion "Cordova/6.0.0"
#define PluginVersion "Cordova/7.0.0"

@interface BatchCordovaPlugin : CDVPlugin <BatchBridgeCallback, BatchLoggerDelegate, BatchMessagingDelegate>

Expand Down
10 changes: 0 additions & 10 deletions dist/src/ios/interop/BatchBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,6 @@ + (NSString *)boolToBridgeString:(BOOL)value
{
// Do nothing
}
else if ([action caseInsensitiveCompare:REGISTER_NOTIFS] == NSOrderedSame)
{
[BatchBridge registerForRemoteNotifications];
}
else if ([action caseInsensitiveCompare:DISMISS_NOTIFS] == NSOrderedSame)
{
[BatchBridge dismissNotifications];
Expand Down Expand Up @@ -483,12 +479,6 @@ + (void)setNotificationTypes:(BatchNotificationType)type
[BatchPush setRemoteNotificationTypes:type];
}

+ (void)registerForRemoteNotifications
{
[BatchPush requestNotificationAuthorization];
[BatchPush refreshToken];
}

+ (void)clearBadge
{
[BatchPush clearBadge];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)registerAsDelegate;

/// Should iOS display notifications even if the app is in foreground?
/// Default: false
/// Default: true
@property (assign) BOOL showForegroundNotifications;

/// Should Batch use the chained delegate's completionHandler responses or force its own, while still calling the chained delegate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ - (instancetype)init
{
self = [super init];
if (self) {
_showForegroundNotifications = false;
_showForegroundNotifications = true;
_shouldUseChainedCompletionHandlerResponse = true;
_isBatchReady = false;
_enqueuedNotificationResponses = [NSMutableArray new];
Expand Down
1 change: 0 additions & 1 deletion dist/src/ios/interop/BatchBridgeShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ if (error == NULL) {\
#define PUSH_REQUEST_AUTHORIZATION @"push.requestAuthorization"
#define PUSH_REQUEST_PROVISIONAL_AUTH @"push.iOS.requestProvisionalAuthorization"

#define REGISTER_NOTIFS @"push.register"
#define DISMISS_NOTIFS @"push.dismissNotifications"
#define CLEAR_BADGE @"push.clearBadge"

Expand Down
14 changes: 14 additions & 0 deletions dist/src/ios/interop/BatchProfileBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ + (void)editAttributes:(NSDictionary*)params
NSLog(@"Batch Bridge - Invalid value for email marketing subscription state. Must be `subscribed` or `unsubscribed`.");
}
}
else if([@"SET_PHONE_NUMBER" isEqualToString:operationName])
{
[editor setPhoneNumber:[BatchBridgeUtils nullableString:operationDescription forKey:@"value"] error:nil];
}
else if([@"SET_SMS_MARKETING_SUB" isEqualToString:operationName]) {
NSString* value = [operationDescription objectForKey:@"value"];
if([[value uppercaseString] isEqualToString:@"SUBSCRIBED"]) {
[editor setSMSMarketingSubscriptionState:BatchSMSSubscriptionStateSubscribed];
} else if ([[value uppercaseString] isEqualToString:@"UNSUBSCRIBED"]) {
[editor setSMSMarketingSubscriptionState: BatchSMSSubscriptionStateUnsubscribed];
} else {
NSLog(@"Batch Bridge - Invalid value for SMS marketing subscription state. Must be `subscribed` or `unsubscribed`.");
}
}
else if ([@"SET_ATTRIBUTE" isEqualToString:operationName])
{
NSString *type = operationDescription[@"type"];
Expand Down
3 changes: 2 additions & 1 deletion src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export enum Push {
SetIOSShowForegroundNotifications = "push.setIOSShowForegroundNotifications",
SetIOSNotifTypes = "push.setIOSNotifTypes",
SetAndroidNotifTypes = "push.setAndroidNotifTypes",
Register = "push.register",
DismissNotifications = "push.dismissNotifications",
ClearBadge = "push.clearBadge",
RefreshToken = "push.iOS.refreshToken",
Expand Down Expand Up @@ -62,6 +61,8 @@ export enum ProfileAttributeOperation {
SetRegion = "SET_REGION",
SetEmail = "SET_EMAIL_ADDRESS",
SetEmailMarketingSubscription = "SET_EMAIL_MARKETING_SUB",
SetPhoneNumber = "SET_PHONE_NUMBER",
SetSMSMarketingSubscription = "SET_SMS_MARKETING_SUB",
SetAttribute = "SET_ATTRIBUTE",
RemoveAttribute = "REMOVE_ATTRIBUTE",
AddToArray = "ADD_TO_ARRAY",
Expand Down
8 changes: 6 additions & 2 deletions src/batchStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class PushStub implements BatchSDK.PushModule {
this.iOSNotificationTypes = iOSNotificationTypes;
}

public registerForRemoteNotifications() {}
public refreshToken() {}
public requestNotificationAuthorization() {}
public requestProvisionalNotificationAuthorization() {}
Expand Down Expand Up @@ -132,13 +131,18 @@ class BatchUserDataEditorStub implements BatchSDK.BatchProfileAttributeEditor {
public setRegion(_region: string | null) {
return this;
}

public setEmailAddress(_email: string | null) {
return this;
}
public setEmailMarketingSubscription(_state: "subscribed" | "unsubscribed") {
return this;
}
public setPhoneNumber(_phoneNumber: string | null) {
return this;
}
public setSMSMarketingSubscription(_state: "subscribed" | "unsubscribed") {
return this;
}
public setAttribute(
_key: string,
_value: string | number | boolean | Date | URL
Expand Down
36 changes: 36 additions & 0 deletions src/modules/profile/profileAttributeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,42 @@ export class BatchProfileAttributeEditor
return this;
}

public setPhoneNumber(phoneNumber: string | null): this {
if (typeof phoneNumber !== "string" && phoneNumber !== null) {
writeBatchLog(
false,
"BatchProfileAttributeEditor - Phone number must be a string or null"
);
return this;
}
this._enqueueOperation(ProfileAttributeOperation.SetPhoneNumber, {
value: phoneNumber,
});
return this;
}

public setSMSMarketingSubscription(
state: "subscribed" | "unsubscribed"
): this {
if (
typeof state !== "string" ||
(state !== "subscribed" && state !== "unsubscribed")
) {
writeBatchLog(
false,
"BatchProfileAttributeEditor - SMS marketing subscription state must be `subscribed` or `unsubscribed`."
);
return this;
}
this._enqueueOperation(
ProfileAttributeOperation.SetSMSMarketingSubscription,
{
value: state,
}
);
return this;
}

public setAttribute(
key: string,
value: string | number | boolean | Date | URL | Array<string>
Expand Down
4 changes: 0 additions & 4 deletions src/modules/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ export class PushModule implements BatchSDK.PushModule {
this.iOSNotificationTypes = iOSNotificationTypes;
}

public registerForRemoteNotifications(): void {
sendToBridge(null, PushActions.Register, null);
}

public refreshToken(): void {
sendToBridge(null, PushActions.RefreshToken, null);
}
Expand Down
Loading