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

Feat: Identity Verification iOS Implementation #1033

Closed
wants to merge 10 commits into 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.7)
- OneSignalXCFramework (5.2.7):
- OneSignalXCFramework/OneSignalComplete (= 5.2.7)
- OneSignalXCFramework/OneSignal (5.2.7):
- 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.7):
- OneSignalXCFramework/OneSignalComplete (5.3.0-beta-01):
- OneSignalXCFramework/OneSignal
- OneSignalXCFramework/OneSignalInAppMessages
- OneSignalXCFramework/OneSignalLocation
- OneSignalXCFramework/OneSignalCore (5.2.7)
- OneSignalXCFramework/OneSignalExtension (5.2.7):
- OneSignalXCFramework/OneSignalCore (5.3.0-beta-01)
- OneSignalXCFramework/OneSignalExtension (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalOutcomes
- OneSignalXCFramework/OneSignalInAppMessages (5.2.7):
- OneSignalXCFramework/OneSignalInAppMessages (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalNotifications
- OneSignalXCFramework/OneSignalOSCore
- OneSignalXCFramework/OneSignalOutcomes
- OneSignalXCFramework/OneSignalUser
- OneSignalXCFramework/OneSignalLiveActivities (5.2.7):
- OneSignalXCFramework/OneSignalLiveActivities (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalOSCore
- OneSignalXCFramework/OneSignalUser
- OneSignalXCFramework/OneSignalLocation (5.2.7):
- OneSignalXCFramework/OneSignalLocation (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalNotifications
- OneSignalXCFramework/OneSignalOSCore
- OneSignalXCFramework/OneSignalUser
- OneSignalXCFramework/OneSignalNotifications (5.2.7):
- OneSignalXCFramework/OneSignalNotifications (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalExtension
- OneSignalXCFramework/OneSignalOutcomes
- OneSignalXCFramework/OneSignalOSCore (5.2.7):
- OneSignalXCFramework/OneSignalOSCore (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalOutcomes (5.2.7):
- OneSignalXCFramework/OneSignalOutcomes (5.3.0-beta-01):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalUser (5.2.7):
- 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: 44e859961f0bc894ddef3e9ae371a041443e11ec
OneSignalXCFramework: c56f9470a6fb23048baf55e02740a09cfd32863c
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.7" />
<pod name="OneSignalXCFramework" spec="5.3.0-beta-01" />
</pods>
</podspec>

Expand Down
2 changes: 2 additions & 0 deletions src/ios/OneSignalPush.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@

- (void)login:(CDVInvokedUrlCommand* _Nonnull)command;
- (void)logout:(CDVInvokedUrlCommand* _Nonnull)command;
- (void)updateUserJwt:(CDVInvokedUrlCommand* _Nonnull)command;
- (void)addUserJwtInvalidatedListener:(CDVInvokedUrlCommand* _Nonnull)command;
jennantilla marked this conversation as resolved.
Show resolved Hide resolved

- (void)addTags:(CDVInvokedUrlCommand* _Nonnull)command;
- (void)removeTags:(CDVInvokedUrlCommand* _Nonnull)command;
Expand Down
18 changes: 17 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,28 @@ - (void)setAlertLevel:(CDVInvokedUrlCommand*)command {
}

- (void)login:(CDVInvokedUrlCommand*)command {
[OneSignal login:command.arguments[0]];
NSString *externalId = command.arguments[0];
NSString *jwtToken = command.arguments.count > 1 ? command.arguments[1] : nil;
jennantilla marked this conversation as resolved.
Show resolved Hide resolved

[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];
}
}

- (void)addTags:(CDVInvokedUrlCommand*)command {
[OneSignal.User addTags:command.arguments[0]];
}
Expand Down
59 changes: 53 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;
jennantilla marked this conversation as resolved.
Show resolved Hide resolved
}

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,58 @@ 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 {
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} jwtToken
*/
updateUserJwt(externalId: string, jwtToken: string): void {
jennantilla marked this conversation as resolved.
Show resolved Hide resolved
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "updateUserJwt", [externalId, jwtToken]);
}

/**
* 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