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 #1038

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
32 changes: 16 additions & 16 deletions example/IonicCapOneSignal/ios/App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,49 @@ PODS:
- Capacitor
- CordovaPluginsStatic (6.0.0):
- CapacitorCordova
- OneSignalXCFramework (= 5.2.9)
- OneSignalXCFramework (5.2.9):
- OneSignalXCFramework/OneSignalComplete (= 5.2.9)
- OneSignalXCFramework/OneSignal (5.2.9):
- OneSignalXCFramework (= 5.3.0-beta-01)
- 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.9):
- OneSignalXCFramework/OneSignalComplete (5.3.0-beta-01):
- OneSignalXCFramework/OneSignal
- OneSignalXCFramework/OneSignalInAppMessages
- OneSignalXCFramework/OneSignalLocation
- OneSignalXCFramework/OneSignalCore (5.2.9)
- OneSignalXCFramework/OneSignalExtension (5.2.9):
- OneSignalXCFramework/OneSignalCore (5.3.0-beta-01)
- OneSignalXCFramework/OneSignalExtension (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalOutcomes
- OneSignalXCFramework/OneSignalInAppMessages (5.2.9):
- OneSignalXCFramework/OneSignalInAppMessages (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalNotifications
- OneSignalXCFramework/OneSignalOSCore
- OneSignalXCFramework/OneSignalOutcomes
- OneSignalXCFramework/OneSignalUser
- OneSignalXCFramework/OneSignalLiveActivities (5.2.9):
- OneSignalXCFramework/OneSignalLiveActivities (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalOSCore
- OneSignalXCFramework/OneSignalUser
- OneSignalXCFramework/OneSignalLocation (5.2.9):
- OneSignalXCFramework/OneSignalLocation (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalNotifications
- OneSignalXCFramework/OneSignalOSCore
- OneSignalXCFramework/OneSignalUser
- OneSignalXCFramework/OneSignalNotifications (5.2.9):
- OneSignalXCFramework/OneSignalNotifications (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalExtension
- OneSignalXCFramework/OneSignalOutcomes
- OneSignalXCFramework/OneSignalOSCore (5.2.9):
- OneSignalXCFramework/OneSignalOSCore (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalOutcomes (5.2.9):
- OneSignalXCFramework/OneSignalOutcomes (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalUser (5.2.9):
- OneSignalXCFramework/OneSignalUser (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalNotifications
- OneSignalXCFramework/OneSignalOSCore
Expand Down Expand Up @@ -97,8 +97,8 @@ SPEC CHECKSUMS:
CapacitorHaptics: 9ebc9363f0e9b8eb4295088a0b474530acf1859b
CapacitorKeyboard: deacbd09d8d1029c3681197fb05d206b721d5f73
CapacitorStatusBar: 2e4369f99166125435641b1908d05f561eaba6f6
CordovaPluginsStatic: 74720072a4a4ab131d56823ddd85736b6bc9f92b
OneSignalXCFramework: f5b2a3c4f130e4c910ead7bb25bed7455e976fbf
CordovaPluginsStatic: ec3f38153034076a0419390445f43486bdca03ce
OneSignalXCFramework: b859cf761f5437ff56a2a9fd158e67d74cd3bcfc

PODFILE CHECKSUM: 178e2a2e451311a871c2b4db713ac4b63d0ebeeb

Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<source url="https://cdn.cocoapods.org/"/>
</config>
<pods use-frameworks="true">
<pod name="OneSignalXCFramework" spec="5.2.9" />
<pod name="OneSignalXCFramework" spec="5.3.0-beta-01" />
</pods>
</podspec>

Expand Down
4 changes: 3 additions & 1 deletion src/ios/OneSignalPush.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#import <OneSignalFramework/OneSignalFramework.h>

@interface OneSignalPush : CDVPlugin <OSNotificationPermissionObserver, OSNotificationLifecycleListener, OSNotificationClickListener, OSPushSubscriptionObserver, OSInAppMessageLifecycleListener, OSInAppMessageClickListener, OSUserStateObserver>
@interface OneSignalPush : CDVPlugin <OSNotificationPermissionObserver, OSNotificationLifecycleListener, OSNotificationClickListener, OSPushSubscriptionObserver, OSInAppMessageLifecycleListener, OSInAppMessageClickListener, OSUserStateObserver, OSUserJwtInvalidatedListener>

- (void)setProvidesNotificationSettingsView:(CDVInvokedUrlCommand* _Nonnull)command;
- (void)addForegroundLifecycleListener:(CDVInvokedUrlCommand* _Nonnull)command;
Expand All @@ -48,6 +48,8 @@

- (void)login:(CDVInvokedUrlCommand* _Nonnull)command;
- (void)logout:(CDVInvokedUrlCommand* _Nonnull)command;
- (void)updateUserJwt:(CDVInvokedUrlCommand* _Nonnull)command;
- (void)addUserJwtInvalidatedListener:(CDVInvokedUrlCommand* _Nonnull)command;

- (void)addTags:(CDVInvokedUrlCommand* _Nonnull)command;
- (void)removeTags:(CDVInvokedUrlCommand* _Nonnull)command;
Expand Down
19 changes: 18 additions & 1 deletion src/ios/OneSignalPush.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
NSString* inAppMessageDidDismissCallbackId;
NSString* inAppMessageClickedCallbackId;
NSString* userObserverCallbackId;
NSString* addUserJwtInvalidatedListenerCallbackId;

OSNotificationClickEvent *actionNotification;
OSNotification *notification;
Expand Down Expand Up @@ -367,13 +368,29 @@ - (void)setAlertLevel:(CDVInvokedUrlCommand*)command {
}

- (void)login:(CDVInvokedUrlCommand*)command {
[OneSignal login:command.arguments[0]];
NSString *externalId = command.arguments[0];
// check if jwt token provided
NSString *jwtToken = command.arguments.count > 1 ? command.arguments[1] : nil;

[OneSignal login:externalId withToken:jwtToken];
}

- (void)logout:(CDVInvokedUrlCommand*)command {
[OneSignal logout];
}

- (void)updateUserJwt:(CDVInvokedUrlCommand*)command {
[OneSignal updateUserJwt:command.arguments[0] withToken:command.arguments[1]];
}

- (void)addUserJwtInvalidatedListener:(CDVInvokedUrlCommand*)command {
bool first = addUserJwtInvalidatedListenerCallbackId == nil;
addUserJwtInvalidatedListenerCallbackId = command.callbackId;
if (first) {
[OneSignal addUserJwtInvalidatedListener:self];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see (void)onUserJwtInvalidatedWithEvent in this PR. Were you able to test the invalidated callback firing?

}
}

- (void)addTags:(CDVInvokedUrlCommand*)command {
[OneSignal.User addTags:command.arguments[0]];
}
Expand Down
60 changes: 54 additions & 6 deletions www/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ import LiveActivities from "./LiveActivitiesNamespace";
// Suppress TS warnings about window.cordova
declare let window: any; // turn off type checking

export interface UserJwtInvalidatedEvent {
externalId: string;
}

export class OneSignalPlugin {
User: User = new User();
Debug: Debug = new Debug();
Expand All @@ -47,6 +51,14 @@ export class OneSignalPlugin {

private _appID = "";

private _userJwtInvalidatedEventListenerList: ((event:UserJwtInvalidatedEvent)=>void)[] = [];

private _processFunctionList(array: ((event:any)=>void)[], param: any): void {
for (let i = 0; i < array.length; i++) {
array[i](param);
}
}

/**
* Initializes the OneSignal SDK. This should be called during startup of the application.
* @param {string} appId
Expand All @@ -64,23 +76,59 @@ export class OneSignalPlugin {
};

/**
* Login to OneSignal under the user identified by the [externalId] provided. The act of logging a user into the OneSignal SDK will switch the [user] context to that specific user.
* @param {string} externalId
* Log in to OneSignal under the user identified by the [externalId] provided. The act of logging a user into the OneSignal SDK will switch the [user] context to that specific user.
* @param {string} externalId
* @param {string} jwtToken - Optional
* @returns void
*/
login(externalId: string): void {
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "login", [externalId]);
login(externalId: string, jwtToken?: string): void {
// if no jwt token, pass null
Copy link
Contributor

@nan-li nan-li Dec 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// if no jwt token, pass null

Is this comment accurate?

const args = jwtToken ? [externalId, jwtToken] : [externalId];
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "login", args);
}

/**
* Logout the user previously logged in via [login]. The [user] property now references a new device-scoped user.
* @param {string} externalId
* Log out the user previously logged in via [login]. The [user] property now references a new device-scoped user.
* @returns void
*/
logout(): void {
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "logout");
}

/**
* Update the JWT token for a user.
* @param {string} externalId
* @param {string} token
*/
updateUserJwt(externalId: string, token: string): void {
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "updateUserJwt", [externalId, token]);
}

/**
* Add a callback that fires when the user's JWT is invalidated.
* @param event
* @param listener
*/
addEventListener(event: "userJwtInvalidated", listener: (event: UserJwtInvalidatedEvent) => void) {
this._userJwtInvalidatedEventListenerList.push(listener as (event: UserJwtInvalidatedEvent) => void);
const userJwtInvalidatedCallBackProcessor = (event: UserJwtInvalidatedEvent) => {
this._processFunctionList(this._userJwtInvalidatedEventListenerList, event);
};
window.cordova.exec(userJwtInvalidatedCallBackProcessor, function(){}, "OneSignalPush", "addUserJwtInvalidatedListener", []);
}

/**
* Remove a UserJwtInvalidated Listener that has been previously added.
* @param event
* @param listener
*/
removeEventListener(event: "userJwtInvalidated", listener: (event: UserJwtInvalidatedEvent) => void) {
let index = this._userJwtInvalidatedEventListenerList.indexOf(listener);
if (index !== -1) {
this._userJwtInvalidatedEventListenerList.splice(index, 1);
}
}

/**
* Determines whether a user must consent to privacy prior to their user data being sent up to OneSignal. This should be set to true prior to the invocation of initialization to ensure compliance.
* @param {boolean} required
Expand Down
Loading