npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ramrnpm/capacitor-azure-notification-hubs

v4.0.4

Published

Capacitor plugin to register push notifications and manage tags via Azure Notification Hub. Tag management is only implemented for ios.

Downloads

7

Readme

Install

npm install @jonz94/capacitor-azure-notification-hubs @capacitor/push-notifications
npx cap sync

iOS

On iOS you must enable the Push Notifications capability. See Setting Capabilities for instructions on how to enable the capability.

After enabling the Push Notifications capability, add the following lines to ios/App/App/AppDelegate.swift:

import UIKit
import Capacitor

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

+    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
+        NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: deviceToken)
+    }
+
+    func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
+        NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
+    }

    // ...

}

Android

The Push Notification API uses Firebase Cloud Messaging SDK for handling notifications. See Set up a Firebase Cloud Messaging client app on Android and follow the instructions for creating a Firebase project and registering your application. There is no need to add the Firebase SDK to your app or edit your app manifest - the Push Notifications provides that for you. All that is required is your Firebase project's google-services.json file added to the module (app-level) directory of your app.

Variables

This plugin will use the following project variables (defined in your app's variables.gradle file):

  • firebaseMessagingVersion version of com.google.firebase:firebase-messaging (default: 23.1.2)
  • azureNotificationHubsVersion version of com.microsoft.azure:notification-hubs-android-sdk-fcm (default: 2.0.0)
  • androidVolleyVersion version of com.android.volley:volley (default: 1.2.1)
  • androidxCoreKTXVersion version of androidx.core:core-ktx (default: 1.12.0)
  • kotlin_version version of org.jetbrains.kotlin:kotlin-stdlib (default: 1.9.10)

Configuration

No configuration required for this plugin.

Usage

import { Device } from '@capacitor/device';
import { PushNotifications } from '@capacitor/push-notifications';
import { AzureNotificationHubs } from '@jonz94/capacitor-azure-notification-hubs';

const addListeners = async () => {
  await AzureNotificationHubs.addListener('registration', token => {
    console.log('Registration token: ', token.value);
  });

  await AzureNotificationHubs.addListener('registrationError', err => {
    console.error('Registration error: ', err.error);
  });
}

const registerNotifications = async () => {
  let permissionStatus = await PushNotifications.checkPermissions();

  if (permissionStatus.receive === 'prompt') {
    permissionStatus = await PushNotifications.requestPermissions();
  }

  if (permissionStatus.receive !== 'granted') {
    throw new Error('User denied permissions!');
  }

  const { identifier } = await Device.getId();

  const myDeviceTag = `${identifier}-${Date.now()}`

  await AzureNotificationHubs.register({
    notificationHubName: 'azure-notification-hub-name',
    connectionString: 'my-connection-string',
    deviceTag: myDeviceTag,
  });
}

API

register(...)

register(info: RegisterInfo) => Promise<void>

Register the app to receive push notifications.

This method will trigger the 'registration' event with the push token or 'registrationError' if there was a problem. It does not prompt the user for notification permissions, use PushNotifications.requestPermissions() from @capacitor/push-notifications first.

| Param | Type | | ---------- | ----------------------------------------------------- | | info | RegisterInfo |

Since: 1.0.0


addTags(...)

addTags(tags: TagsInfo) => Promise<void>

| Param | Type | | ---------- | --------------------------------------------- | | tags | TagsInfo |


clearTags()

clearTags() => Promise<void>

clearAndAddTags(...)

clearAndAddTags(tags: TagsInfo) => Promise<void>

| Param | Type | | ---------- | --------------------------------------------- | | tags | TagsInfo |


addListener('registration', ...)

addListener(eventName: 'registration', listenerFunc: (token: Token) => void) => Promise<PluginListenerHandle>

Called when the push notification registration finishes without problems.

Provides the push notification token.

| Param | Type | | ------------------ | ----------------------------------------------------------- | | eventName | 'registration' | | listenerFunc | (token: Token) => void |

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


addListener('registrationError', ...)

addListener(eventName: 'registrationError', listenerFunc: (error: RegistrationError) => void) => Promise<PluginListenerHandle>

Called when the push notification registration finished with problems.

Provides an error with the registration problem.

| Param | Type | | ------------------ | ----------------------------------------------------------------------------------- | | eventName | 'registrationError' | | listenerFunc | (error: RegistrationError) => void |

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all native listeners for this plugin.

Since: 1.0.0


Interfaces

RegisterInfo

| Prop | Type | Description | Since | | ------------------------- | ------------------- | ----------------------------- | ----- | | notificationHubName | string | The notification hub name. | 1.0.0 | | connectionString | string | The connection string. | 1.0.0 | | tags | string | Comma separated list of tags. | 1.0.0 |

TagsInfo

| Prop | Type | | ---------- | --------------------- | | tags | string[] |

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |

Token

| Prop | Type | Description | Since | | ----------- | ------------------- | ------------------------------------------------------------------------ | ----- | | value | string | On iOS it contains the APNS token. On Android it contains the FCM token. | 1.0.0 |

RegistrationError

| Prop | Type | Description | Since | | ----------- | ------------------- | -------------------------------------------------- | ----- | | error | string | Error message describing the registration failure. | 1.0.0 |

Changelog

See CHANGELOG.md.

License

See LICENSE.