This plugin provides APIs for handling push notifications in Tauri applications, supporting iOS platforms.
Install the Core plugin by adding the following to your Cargo.toml
file:
[dependencies]
tauri-plugin-notifications = { git = "https://github.com/inkibra/tauri-plugins", tag = "@inkibra/tauri-plugin-notifications@VERSION" }
Before installing the JavaScript bindings, configure npm to use the GitHub Packages registry:
npm config set @inkibra:registry https://npm.pkg.github.com
# or
yarn config set @inkibra:registry https://npm.pkg.github.com
# or
pnpm config set @inkibra:registry https://npm.pkg.github.com
Then install the JavaScript bindings:
npm add @inkibra/tauri-plugin-notifications
# or
yarn add @inkibra/tauri-plugin-notifications
# or
pnpm add @inkibra/tauri-plugin-notifications
First, register the core plugin with Tauri:
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_notifications::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Then use the plugin in your JavaScript code:
import {
checkPermissions,
requestPermissions,
registerForRemoteNotifications,
watchNotifications
} from '@inkibra/tauri-plugin-notifications';
// Check notification permissions
const permissionStatus = await checkPermissions();
// Request notification permissions
const requestResult = await requestPermissions();
// Register for remote notifications
const registrationResult = await registerForRemoteNotifications();
// Watch for notification events
await watchNotifications((event) => {
console.log('Notification received:', event);
});
-
checkPermissions(): Promise<NotificationPermissionStatus>
- Checks current notification permission status
- Returns status as "prompt", "denied", or "granted"
-
requestPermissions(): Promise<NotificationPermissionStatus>
- Requests notification permissions from the user
- Returns the resulting permission status
-
checkRegistrationStatus(): Promise<NotificationRegistrationStatus>
- Checks if the app is registered for remote notifications
- Returns registration status and device token if available
-
registerForRemoteNotifications(): Promise<NotificationRegistrationResult>
- Registers the app for remote notifications
- Returns success status and device token or error message
-
watchNotifications(callback: (event: NotificationEvent) => void): Promise<WatchNotificationResult>
- Sets up a listener for notification events
- Returns success status of the watch operation
interface NotificationPermissionStatus {
status: "prompt" | "denied" | "granted";
}
interface NotificationRegistrationStatus {
isRegistered: boolean;
token?: string;
}
interface NotificationRegistrationResult {
success: boolean;
token?: string;
error?: string;
}
type NotificationEventType =
| "BACKGROUND_TAP"
| "FOREGROUND_TAP"
| "FOREGROUND_DELIVERY"
| "BACKGROUND_DELIVERY";
interface NotificationEvent {
type: NotificationEventType;
payload: Record<string, string>;
}
interface WatchNotificationResult {
success: boolean;
}
- Enable Push Notifications capability in your Xcode project
- Configure your Apple Developer account for push notifications
- Add required entitlements:
-
aps-environment
(development or production)
-
- Configure your app's Info.plist with required background modes:
- Remote notifications
Platform | Status |
---|---|
iOS | ✅ |
Desktop | ❌ |
Desktop platforms will return appropriate "not supported" responses for all operations.
import {
requestPermissions,
registerForRemoteNotifications,
watchNotifications
} from '@inkibra/tauri-plugin-notifications';
async function setupNotifications() {
try {
// Request permissions
const permissionResult = await requestPermissions();
if (permissionResult.status === 'granted') {
// Register for notifications
const registration = await registerForRemoteNotifications();
if (registration.success) {
console.log('Successfully registered for notifications');
console.log('Device token:', registration.token);
} else {
console.error('Registration failed:', registration.error);
}
} else {
console.log('Notification permissions not granted:', permissionResult.status);
}
// Set up notification listener
const watchResult = await watchNotifications((event) => {
switch (event.type) {
case 'BACKGROUND_TAP':
console.log('User tapped notification in background');
break;
case 'FOREGROUND_TAP':
console.log('User tapped notification in foreground');
break;
case 'FOREGROUND_DELIVERY':
console.log('Notification received in foreground');
break;
case 'BACKGROUND_DELIVERY':
console.log('Notification received in background');
break;
}
console.log('Notification payload:', event.payload);
});
if (watchResult.success) {
console.log('Successfully set up notification listener');
}
} catch (error) {
console.error('Error setting up notifications:', error);
}
}
// Call the setup function
setupNotifications();
We welcome contributions! Please feel free to submit issues and pull requests.
This plugin is licensed under either of:
- Apache License, Version 2.0
- MIT license
at your option.
This plugin is maintained by the Inkibra team and the Tauri community.