https://github.com/essent/nativescript-urban-airship
Urban airship plugin interface for NativeScript
https://github.com/essent/nativescript-urban-airship
Last synced: over 1 year ago
JSON representation
Urban airship plugin interface for NativeScript
- Host: GitHub
- URL: https://github.com/essent/nativescript-urban-airship
- Owner: Essent
- License: other
- Created: 2017-01-17T10:35:50.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-08-18T12:03:12.000Z (almost 4 years ago)
- Last Synced: 2025-04-15T05:54:57.224Z (over 1 year ago)
- Language: TypeScript
- Size: 2.53 MB
- Stars: 6
- Watchers: 1
- Forks: 3
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NativeScript plugin for Urban Airship
[](https://www.npmjs.com/package/nativescript-urban-airship)
This is a plugin to use the [Urban Airship](https://www.urbanairship.com/) SDK (Android v15.0.0, iOS v15.0.1) with NativeScript.
For iOS this plugin uses APNS and for Android it uses FCM.
## Requirements
* Xcode 12.x
* Android SDK 29
* NativeScript CLI 7.x
* Urban Airship account
## Installation
Run the following command from the root of your project:
```console
npm install nativescript-urban-airship
```
### Setup
First create a file with all your Urban Airship setting ([example](./demo/app/urbanAirshipSettings.ts)).
#### Android
1. Create a custom native android.app.Application in your app folder ([example](./demo/app/application.android.ts)) that calls `startUp()` with your settings in the `onCreate()`:
```ts
public onCreate(): void {
super.onCreate();
NsUrbanAirship.getInstance().startUp(urbanAirshipSettings, this);
}
```
Use that custom application in the application tag in your `AndroidManifest.xml` ([example](./demo/app/App_Resources/Android/src/main/AndroidManifest.xml#L22)).
2. Place your `google-services.json` in your `App_Resources/Android` folder. This json file can be created using the [setup of FCM](https://firebase.google.com/docs/android/setup).
3. Copy the hooks [firebase-adjust-gradle.js](./demo/hooks/after-prepare/firebase-adjust-gradle.js) and [firebase-copy-google-services.js](./demo/hooks/after-prepare/firebase-copy-google-services.js) from our demo app to the `after-prepare` folder of your app.
4. Specify the right `applicationId` in your app's `app.gradle` ([example](./demo/app/App_Resources/Android/app.gradle#L10)).
5. Specify the right `id` in your app's `package.json`.
#### iOS
Create a custom UIApplicationDelegate in your app folder ([example](./demo/app/custom.delegate.ts)) that calls `startUp()` with your settings in the `applicationDidFinishLaunchingWithOptions()`:
```ts
applicationDidFinishLaunchingWithOptions(application: UIApplication, launchOptions: NSDictionary): boolean {
NsUrbanAirship.getInstance().startUp(urbanAirshipSettings, null);
return true;
};
```
Import that custom UIApplicationDelegate in your `app.ts` ([example](./demo/app/app.ts)).
#### Swift Version
Since version 6.0 of the plugin, if the project does not already include it, it is necessary to raise the Swift version to 5.0 by adding the following line to your Podfile.
```ts
config.build_settings['SWIFT_VERSION'] = '5.0'
```
#### Styling the Preference Center
In order to style the Preference Center on iOS, it is necesssary to create a AirshipPreferenceCenterStyle.plist file and populate it according to the information that can be found [here](https://docs.airship.com/platform/ios/preference-center/).
NOTE: At the time of writing this, all the possible parameters have not been listed on the page mentioned and can be found [here](https://github.com/urbanairship/ios-library/blob/main/Airship/AirshipPreferenceCenter/Source/PreferenceCenterStyle.swift).
### Known Issues
When using webpack, calling `startUp()` on Android in a custom native android.app.Application is not working, in that case it is better to call the native function instead of `startUp()`:
```ts
public onCreate(): void {
super.onCreate();
const options = new com.urbanairship.AirshipConfigOptions.Builder()
.setDevelopmentAppKey(urbanAirshipSettings.developmentAppKey)
.setDevelopmentAppSecret(urbanAirshipSettings.developmentAppSecret)
.setProductionAppKey(urbanAirshipSettings.productionAppKey)
.setProductionAppSecret(urbanAirshipSettings.productionAppSecret)
.setInProduction(urbanAirshipSettings.inProduction)
.build();
com.urbanairship.UAirship.takeOff(this, options);
}
```
### Optional functions
#### Setting Named User Id
To register a named user id call `registerUser()`.
```ts
NsUrbanairship.getInstance().registerUser('MY_NEW_USER_ID');
```
#### Removing Named User Id
To remove a named user id call `unRegisterUser()`.
```ts
NsUrbanairship.getInstance().unRegisterUser();
```
#### Enabling User Notifications
To set user notifications to enabled call `notificationOptIn()`.
```ts
NsUrbanairship.getInstance().notificationOptIn();
```
#### Disabling User Notifications
To set user notifications to disabled call `notificationOptOut()`.
```ts
NsUrbanairship.getInstance().notificationOptOut();
```
#### Getting Enabled User Notifications
To get the status of enabled push notifications call `isOptIn()`, this will return true or false.
```ts
NsUrbanairship.getInstance().isOptIn();
```
#### Getting Channel ID
To get the channel ID call `getChannelID()`, this will return a string.
```ts
NsUrbanairship.getInstance().getChannelID();
```
#### Getting Registration Token
To get the registration token (APNS token for iOS and FCM token for Android) call `getRegistrationToken()`, this will return a string.
```ts
NsUrbanairship.getInstance().getRegistrationToken();
```
#### Resetting Badge Count (iOS only)
To reset the badge count call `resetBadgeCount()`.
```ts
NsUrbanairship.getInstance().resetBadgeCount();
```
#### Opening Preference Center
To open the preference center call `openPreferenceCenter()`.
```ts
NsUrbanairship.getInstance().openPreferenceCenter('PREFERENCE_CENTER_ID');
```