NativeScript WonderPush
A WonderPush SDK wrapper.
Prerequisites / Requirements
- WonderPush account
- Firebase Account
Installation
Install the plugin
tns plugin add nativescript-wonderpushAndroid
Fill your Firebase credentials in the dashboard
- Locate your Server Key and Sender ID in the Firebase project Cloud Messaging settings.
- Go to your WonderPush dashboard, in the Settings / Configuration page, select the Android app tab.
-
Paste the Server key.
-
Click Update.
Configure SDK
- Configure the WonderPush Android SDK from your
app/App_Resources/app.gradlefile:
android {
defaultConfig {
// Note that it's important to keep the double quotes as part of the third argument
// as this represents a string in Java code
buildConfigField 'String', 'WONDERPUSH_CLIENT_ID', '"YOUR_CLIENT_ID"'
buildConfigField 'String', 'WONDERPUSH_CLIENT_SECRET', '"YOUR_CLIENT_SECRET"'
buildConfigField 'String', 'WONDERPUSH_SENDER_ID', '"YOUR_SENDER_ID"'
}
}
Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with the appropriate values you find in the Settings / Configuration page, in the Android app tab.
Replace YOUR_SENDER_ID with the Firebase Sender ID from previous step
Note that it's important to keep the double quotes as part of the third argument as this represents a string in Java code.
iOS
Upload your push certificate
Go to Settings / Configuration, choose the iOS app tab and fill in:
- your push certificate by clicking the Browse button,
- the push certificate password if appropriate,
- the Push environment (choose Development for testing with an app deployed via Xcode, and Production for an app deployed on the AppStore).
Add required code
Take note of your Client ID and Client Secret from the iOS app tab of the Settings / Configuration page:
Open your main.ts (Angular) or your app.ts (TypeScript) and add the following, adapting YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with the values you've noted above:
import * as app from "tns-core-modules/application";
import * as application from "tns-core-modules/application";
import {WonderPushWrapper} from 'nativescript-wonderpush';
if (application.ios) {
class AppDelegate extends UIResponder implements UIApplicationDelegate {
public static ObjCProtocols = [UIApplicationDelegate];
public applicationWillFinishLaunchingWithOptions(app: UIApplication, launchOptions: NSDictionary<string, any>): boolean {
try {
WonderPushWrapper.setClientIdSecret("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
WonderPushWrapper.setupDelegateForApplication(app);
WonderPushWrapper.setupDelegateForUserNotificationCenter(app);
} catch (error) {
console.error('error', error);
}
return true;
}
}
application.ios.delegate = AppDelegate;
}
Usage
Initialization
With Android, you must initialize the SDK :
WonderPushWrapper.init();We have nothing to do with iOS.
Subscribe & unsubscribe to notifications
- To subscribe :
WonderPushWrapper.subscribeToNotifications();- To unsubscribe :
WonderPushWrapper.unsubscribeFromNotifications();API
| Method | Return | Usage | Platform |
|---|---|---|---|
| init() | void | WonderPushWrapper.init() |
Android only |
| getInstallationId() | string | WonderPushWrapper.getInstallationId() |
Android & iOS |
| getDeviceId() | string | WonderPushWrapper.getDeviceId() |
Android & iOS |
| isSubscribedToNotifications() | boolean | WonderPushWrapper.init() |
Android & iOS |
| subscribeToNotifications() | void | WonderPushWrapper.subscribeToNotifications() |
Android & iOS |
| unsubscribeFromNotifications() | void | WonderPushWrapper.unsubscribeFromNotifications() |
Android & iOS |
| setUserId(newId: string) | void | WonderPushWrapper.setUserId(newId) |
Android & iOS |
| getUserId() | string | WonderPushWrapper.getUserId() |
Android & iOS |
| getPushToken() | string | WonderPushWrapper.getPushToken() |
Android & iOS |
| getAccessToken() | string | WonderPushWrapper.getAccessToken() |
Android & iOS |
| getProperties() | any | WonderPushWrapper.getProperties() |
Android & iOS |
| getUserConsent() | boolean | WonderPushWrapper.getUserConsent() |
Android & iOS |
| setUserConsent(newUserConsent: boolean) | void | WonderPushWrapper.setUserConsent(newUserConsent) |
Android & iOS |
| clearAllData() | void | WonderPushWrapper.clearAllData() |
Android & iOS |
| setClientIdSecret(clientId: string, clientSecret: string) | void | WonderPushWrapper.setClientIdSecret(clientId, clientSecret) |
iOS only |
| setupDelegateForApplication(application: UIApplication) | WonderPushWrapper.setupDelegateForApplication(app) |
iOS only | |
| setupDelegateForUserNotificationCenter(application: UIApplication) | WonderPushWrapper.setupDelegateForUserNotificationCenter(app) |
iOS only |
License
Apache License Version 2.0, January 2004



