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

Feature: Identity Verification iOS Implementation #1761

Open
wants to merge 4 commits into
base: main
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
34 changes: 17 additions & 17 deletions examples/RNOneSignalTS/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,48 @@ PODS:
- React-jsi (= 0.64.4)
- ReactCommon/turbomodule/core (= 0.64.4)
- glog (0.3.5)
- OneSignalXCFramework (5.2.1):
- OneSignalXCFramework/OneSignalComplete (= 5.2.1)
- OneSignalXCFramework/OneSignal (5.2.1):
- OneSignalXCFramework (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalComplete (= 5.3.0-beta-01)
- OneSignalXCFramework/OneSignal (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalExtension
- OneSignalXCFramework/OneSignalLiveActivities
- OneSignalXCFramework/OneSignalNotifications
- OneSignalXCFramework/OneSignalOSCore
- OneSignalXCFramework/OneSignalOutcomes
- OneSignalXCFramework/OneSignalUser
- OneSignalXCFramework/OneSignalComplete (5.2.1):
- OneSignalXCFramework/OneSignalComplete (5.3.0-beta-01):
- OneSignalXCFramework/OneSignal
- OneSignalXCFramework/OneSignalInAppMessages
- OneSignalXCFramework/OneSignalLocation
- OneSignalXCFramework/OneSignalCore (5.2.1)
- OneSignalXCFramework/OneSignalExtension (5.2.1):
- OneSignalXCFramework/OneSignalCore (5.3.0-beta-01)
- OneSignalXCFramework/OneSignalExtension (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalOutcomes
- OneSignalXCFramework/OneSignalInAppMessages (5.2.1):
- OneSignalXCFramework/OneSignalInAppMessages (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalNotifications
- OneSignalXCFramework/OneSignalOSCore
- OneSignalXCFramework/OneSignalOutcomes
- OneSignalXCFramework/OneSignalUser
- OneSignalXCFramework/OneSignalLiveActivities (5.2.1):
- OneSignalXCFramework/OneSignalLiveActivities (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalOSCore
- OneSignalXCFramework/OneSignalUser
- OneSignalXCFramework/OneSignalLocation (5.2.1):
- OneSignalXCFramework/OneSignalLocation (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalNotifications
- OneSignalXCFramework/OneSignalOSCore
- OneSignalXCFramework/OneSignalUser
- OneSignalXCFramework/OneSignalNotifications (5.2.1):
- OneSignalXCFramework/OneSignalNotifications (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalExtension
- OneSignalXCFramework/OneSignalOutcomes
- OneSignalXCFramework/OneSignalOSCore (5.2.1):
- OneSignalXCFramework/OneSignalOSCore (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalOutcomes (5.2.1):
- OneSignalXCFramework/OneSignalOutcomes (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalUser (5.2.1):
- OneSignalXCFramework/OneSignalUser (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalNotifications
- OneSignalXCFramework/OneSignalOSCore
Expand Down Expand Up @@ -249,8 +249,8 @@ PODS:
- React-jsi (= 0.64.4)
- React-perflogger (= 0.64.4)
- React-jsinspector (0.64.4)
- react-native-onesignal (5.2.1):
- OneSignalXCFramework (= 5.2.1)
- react-native-onesignal (5.2.6):
- OneSignalXCFramework (= 5.3.0-beta-01)
- React (< 1.0.0, >= 0.13.0)
- React-perflogger (0.64.4)
- React-RCTActionSheet (0.64.4):
Expand Down Expand Up @@ -423,7 +423,7 @@ SPEC CHECKSUMS:
FBLazyVector: fa8275d5086566e22a26ddc385ab5772e7f9b1bd
FBReactNativeSpec: ac29642c312b20b463b263a24f2472d03b7cd008
glog: 73c2498ac6884b13ede40eda8228cb1eee9d9d62
OneSignalXCFramework: fbafb3b4964a37f8b0ff273419d1c0e5ac0e07d6
OneSignalXCFramework: b859cf761f5437ff56a2a9fd158e67d74cd3bcfc
RCT-Folly: ec7a233ccc97cc556cf7237f0db1ff65b986f27c
RCTRequired: f85fa00af016059cf88b90b8f8ff9a6af9e4b6c3
RCTTypeSafety: 5279aaf0fb1ad715cbbbbee32d5c98c72598bc9c
Expand All @@ -435,7 +435,7 @@ SPEC CHECKSUMS:
React-jsi: 64f80675a66899bf0f4a58b8e3908966fa516234
React-jsiexecutor: 8c077bef1c64430b6034f27df1000d194551e2eb
React-jsinspector: d4f6973dd474357dbaaf6f52f31ffc713bf3e766
react-native-onesignal: 77a5dfd158b6c190243af73e2a9fc724130fbff5
react-native-onesignal: 0585516e173251088db93a05aff996c32d6e6b90
React-perflogger: 5a890ca0911669421b7611661e9b58f91c805f5c
React-RCTActionSheet: bd180e0879f8424a73650c5c28fbef4f3b5b27fb
React-RCTAnimation: 1004d2b4be1f2cedfdc4cb2326adc95b989e6c6b
Expand Down
7,341 changes: 7,341 additions & 0 deletions examples/RNOneSignalTS/yarn.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions ios/RCTOneSignal/RCTOneSignal.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ - (void)onDidDismissInAppMessage:(OSInAppMessageDidDismissEvent * _Nonnull)event
[self sendEvent:OSEventString(InAppMessageDidDismiss) withBody:[event jsonRepresentation]];
}

- (void)onUserJwtInvalidated:(OSUserJwtInvalidatedEvent * _Nonnull)event {
[self sendEvent:OSEventString(UserJwtInvalidated) withBody:[event jsonRepresentation]];
}

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Expand Down
3 changes: 2 additions & 1 deletion ios/RCTOneSignal/RCTOneSignalEventEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ typedef NS_ENUM(NSInteger, OSNotificationEventTypes) {
InAppMessageDidDisplay,
InAppMessageWillDismiss,
InAppMessageDidDismiss,
UserJwtInvalidated,
};

#define OSNotificationEventTypesArray @[@"OneSignal-permissionChanged",@"OneSignal-subscriptionChanged",@"OneSignal-userStateChanged",@"OneSignal-notificationWillDisplayInForeground",@"OneSignal-notificationClicked",@"OneSignal-inAppMessageClicked", @"OneSignal-inAppMessageWillDisplay", @"OneSignal-inAppMessageDidDisplay", @"OneSignal-inAppMessageWillDismiss", @"OneSignal-inAppMessageDidDismiss"]
#define OSNotificationEventTypesArray @[@"OneSignal-permissionChanged",@"OneSignal-subscriptionChanged",@"OneSignal-userStateChanged",@"OneSignal-notificationWillDisplayInForeground",@"OneSignal-notificationClicked",@"OneSignal-inAppMessageClicked", @"OneSignal-inAppMessageWillDisplay", @"OneSignal-inAppMessageDidDisplay", @"OneSignal-inAppMessageWillDismiss", @"OneSignal-inAppMessageDidDismiss", @"OneSignal-userJwtInvalidated"]

#define OSEventString(enum) [OSNotificationEventTypesArray objectAtIndex:enum]

Expand Down
21 changes: 19 additions & 2 deletions ios/RCTOneSignal/RCTOneSignalEventEmitter.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ @implementation RCTOneSignalEventEmitter {
BOOL _hasAddedNotificationForegroundLifecycleListener;
BOOL _hasAddedInAppMessageClickListener;
BOOL _hasAddedInAppMessageLifecycleListener;
BOOL _hasAddedUserJwtInvalidatedListener;
NSMutableDictionary* _preventDefaultCache;
NSMutableDictionary* _notificationWillDisplayCache;
}
Expand Down Expand Up @@ -104,14 +105,30 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
[OneSignal initialize:appId withLaunchOptions:NULL];
}

RCT_EXPORT_METHOD(login:(NSString *)externalId) {
[OneSignal login:externalId];
RCT_EXPORT_METHOD(login:(NSString *)externalId jwtToken:(NSString *)jwtToken) {
// Pass nil if jwtToken is not provided
if (jwtToken == (id)[NSNull null]) {
jwtToken = nil;
}

[OneSignal login:externalId withToken:jwtToken];
}

RCT_EXPORT_METHOD(logout) {
[OneSignal logout];
}

RCT_EXPORT_METHOD(updateUserJwt:(NSString *)externalId jwtToken:(NSString *)jwtToken) {
[OneSignal updateUserJwt:externalId withToken:jwtToken];
}

RCT_EXPORT_METHOD(addUserJwtInvalidatedListener) {
if (!_hasAddedUserJwtInvalidatedListener) {
[OneSignal addUserJwtInvalidatedListener:[RCTOneSignal sharedInstance]];
_hasAddedUserJwtInvalidatedListener = true;
}
}

RCT_EXPORT_METHOD(enterLiveActivity:(NSString *)activityId
withToken:(NSString *)token
withResponse:(RCTResponseSenderBlock)callback) {
Expand Down
2 changes: 1 addition & 1 deletion react-native-onesignal.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ Pod::Spec.new do |s|
# pod 'React', :path => '../node_modules/react-native/'

# The Native OneSignal-iOS-SDK XCFramework from cocoapods.
s.dependency 'OneSignalXCFramework', '5.2.7'
s.dependency 'OneSignalXCFramework', '5.3.0-beta-01'
end
2 changes: 2 additions & 0 deletions src/events/EventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
IN_APP_MESSAGE_WILL_DISMISS,
IN_APP_MESSAGE_DID_DISMISS,
IN_APP_MESSAGE_DID_DISPLAY,
USER_JWT_INVALIDATED,
} from './events';
import OSNotification from '../OSNotification';

Expand All @@ -29,6 +30,7 @@ const eventList = [
IN_APP_MESSAGE_WILL_DISMISS,
IN_APP_MESSAGE_DID_DISMISS,
IN_APP_MESSAGE_DID_DISPLAY,
USER_JWT_INVALIDATED,
];

export default class EventManager {
Expand Down
1 change: 1 addition & 0 deletions src/events/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export const IN_APP_MESSAGE_DID_DISMISS = 'OneSignal-inAppMessageDidDismiss';
export const PERMISSION_CHANGED = 'OneSignal-permissionChanged';
export const SUBSCRIPTION_CHANGED = 'OneSignal-subscriptionChanged';
export const USER_STATE_CHANGED = 'OneSignal-userStateChanged';
export const USER_JWT_INVALIDATED = 'OneSignal-userJwtInvalidated';
43 changes: 41 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
NOTIFICATION_WILL_DISPLAY,
PERMISSION_CHANGED,
SUBSCRIPTION_CHANGED,
USER_JWT_INVALIDATED,
USER_STATE_CHANGED,
} from './events/events';
import {
Expand Down Expand Up @@ -53,6 +54,10 @@
Verbose,
}

export interface UserJwtInvalidatedEvent {
externalId?: string;
}

// Internal wrapper notification permission state that is being updated by the permission change handler.
let notificationPermission = false;

Expand Down Expand Up @@ -99,10 +104,10 @@
* If your integration is user-centric, or you want the ability to identify the user beyond the current device, the
* login method should be called to identify the user.
*/
export function login(externalId: string) {
export function login(externalId: string, jwtToken?: string) {
if (!isNativeModuleLoaded(RNOneSignal)) return;

RNOneSignal.login(externalId);
RNOneSignal.login(externalId, jwtToken || null);
}

/**
Expand All @@ -115,6 +120,40 @@
RNOneSignal.logout();
}

/**
* Update the JWT token for a user.
*/
export function updateUserJwt(externalId: string, jwtToken: string) {
if (!isNativeModuleLoaded(RNOneSignal)) return;

RNOneSignal.updateUserJwt(externalId, jwtToken);
}

/** Add a callback that fires when the user's JWT is invalidated. */
export function addEventListener(
event: 'userJwtInvalidated',
listener: (event: UserJwtInvalidatedEvent) => void,
) {
if (!isNativeModuleLoaded(RNOneSignal)) return;

isValidCallback(listener);
RNOneSignal.addUserJwtInvalidatedListener();
eventManager.addEventListener<UserJwtInvalidatedEvent>(
USER_JWT_INVALIDATED,
listener,
);
}

/** Clears current UserJwtInvalidated listeners. */
export function removeEventListener(
event: 'userJwtInvalidated',
listener: (event: UserJwtInvalidatedEvent) => void,
) {
if (!isNativeModuleLoaded(RNOneSignal)) return;

eventManager.removeEventListener(USER_JWT_INVALIDATED, listener);
}

/** For GDPR users, your application should call this method before setting the App ID. */
export function setConsentRequired(required: boolean) {
if (!isNativeModuleLoaded(RNOneSignal)) return;
Expand Down Expand Up @@ -287,7 +326,7 @@
export namespace User {
export namespace pushSubscription {
/** Add a callback that fires when the OneSignal subscription state changes. */
export function addEventListener(

Check warning on line 329 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

'addEventListener' is already declared in the upper scope on line 451 column 21
event: 'change',
listener: (event: PushSubscriptionChangedState) => void,
) {
Expand All @@ -302,7 +341,7 @@
}

/** Clears current subscription observers. */
export function removeEventListener(

Check warning on line 344 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

'removeEventListener' is already declared in the upper scope on line 466 column 21
event: 'change',
listener: (event: PushSubscriptionChangedState) => void,
) {
Expand Down Expand Up @@ -409,7 +448,7 @@
* Add a callback that fires when the OneSignal user state changes.
* Important: When using the observer to retrieve the onesignalId, check the externalId as well to confirm the values are associated with the expected user.
*/
export function addEventListener(

Check warning on line 451 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

'addEventListener' is already declared in the upper scope on line 133 column 19
event: 'change',
listener: (event: UserChangedState) => void,
) {
Expand All @@ -424,7 +463,7 @@
}

/** Clears current user state observers. */
export function removeEventListener(

Check warning on line 466 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

'removeEventListener' is already declared in the upper scope on line 148 column 19
event: 'change',
listener: (event: UserChangedState) => void,
) {
Expand Down Expand Up @@ -692,7 +731,7 @@

/**
* Add listeners for notification click and/or lifecycle events. */
export function addEventListener<K extends NotificationEventName>(

Check warning on line 734 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

'addEventListener' is already declared in the upper scope on line 133 column 19
event: K,
listener: (event: NotificationEventTypeMap[K]) => void,
): void {
Expand Down Expand Up @@ -723,7 +762,7 @@

/**
* Remove listeners for notification click and/or lifecycle events. */
export function removeEventListener<K extends NotificationEventName>(

Check warning on line 765 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

'removeEventListener' is already declared in the upper scope on line 148 column 19
event: K,
listener: (event: NotificationEventTypeMap[K]) => void,
): void {
Expand Down Expand Up @@ -785,7 +824,7 @@
/**
* Add listeners for In-App Message click and/or lifecycle events.
*/
export function addEventListener<K extends InAppMessageEventName>(

Check warning on line 827 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

'addEventListener' is already declared in the upper scope on line 133 column 19
event: K,
listener: (event: InAppMessageEventTypeMap[K]) => void,
): void {
Expand Down Expand Up @@ -835,7 +874,7 @@
/**
* Remove listeners for In-App Message click and/or lifecycle events.
*/
export function removeEventListener<K extends InAppMessageEventName>(

Check warning on line 877 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

'removeEventListener' is already declared in the upper scope on line 148 column 19
event: K,
listener: (obj: InAppMessageEventTypeMap[K]) => void,
): void {
Expand Down
Loading