feat: 添加原生通知桥接功能及相关配置
This commit is contained in:
32
src/lib/notificationBridge.js
Normal file
32
src/lib/notificationBridge.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Capacitor, registerPlugin } from '@capacitor/core'
|
||||
|
||||
// Web 端的兜底实现:保证浏览器环境下不会报错
|
||||
const webFallback = {
|
||||
async hasPermission() {
|
||||
return { granted: true }
|
||||
},
|
||||
async requestPermission() {
|
||||
return { granted: true }
|
||||
},
|
||||
async getPendingNotifications() {
|
||||
return { notifications: [] }
|
||||
},
|
||||
async acknowledgeNotification() {
|
||||
return { acknowledged: true }
|
||||
},
|
||||
async clearNotifications() {
|
||||
return { cleared: true }
|
||||
},
|
||||
}
|
||||
|
||||
const NotificationBridge = registerPlugin('NotificationBridge', {
|
||||
web: () => webFallback,
|
||||
})
|
||||
|
||||
export const isNativeNotificationBridgeAvailable = () =>
|
||||
typeof Capacitor.isNativePlatform === 'function'
|
||||
? Capacitor.isNativePlatform()
|
||||
: Capacitor.getPlatform() !== 'web'
|
||||
|
||||
export default NotificationBridge
|
||||
|
||||
Reference in New Issue
Block a user