capacitor-otto-onesignal
v1.0.0
Published
Custom Capacitor plugin for the OneSignal native SDKs.
Maintainers
Readme
capacitor-otto-onesignal
Custom Capacitor plugin for the OneSignal native SDKs.
Install
npm install capacitor-otto-onesignal
npx cap syncCapacitor config
You can initialize OneSignal manually from JavaScript, or auto-initialize it from Capacitor config on plugin load.
// capacitor.config.ts
plugins: {
OttoOneSignal: {
appId: 'YOUR_ONESIGNAL_APP_ID',
consentRequired: false,
consentGiven: true,
logLevel: 6,
},
}Log levels follow OneSignal’s 0-6 scale:
0: none1: fatal2: error3: warn4: info5: debug6: verbose
Important host-app setup
This plugin wraps the native SDKs, but OneSignal still requires native app setup in the consuming app.
Android
At minimum, make sure the host app:
- has Firebase Cloud Messaging configured in OneSignal
- can resolve the OneSignal SDK dependency
- calls the plugin
initialize()as early as practical if you do not use config-based auto-init
Reference: Android SDK setup
iOS
The host app still needs Apple-side notification setup. In particular:
- Push Notifications capability enabled
- Background Modes with remote notifications enabled
- an App Group configured
- a
OneSignalNotificationServiceExtensiontarget added to the app - the app target linked with
OneSignalFramework - the extension target linked with
OneSignalExtension
Reference: iOS SDK setup
If your app prompts for notifications, keep the normal iOS usage description keys up to date in the consuming app.
Usage
import { OttoOneSignal } from 'capacitor-otto-onesignal';
await OttoOneSignal.initialize({
appId: 'YOUR_ONESIGNAL_APP_ID',
logLevel: 6,
});
await OttoOneSignal.requestPermission({ fallbackToSettings: false });
await OttoOneSignal.login({ externalId: 'user-123' });
await OttoOneSignal.addTags({
tags: {
plan: 'pro',
locale: 'en',
},
});
const state = await OttoOneSignal.getUserState();
console.log(state.pushSubscriptionId, state.pushToken);API
initializerequestPermissionloginlogoutaddTagaddTagsremoveTagremoveTagsgetTagsgetPermissionStategetUserStateoptInoptOutclearAllNotifications
