feat(notification): integrate expo-notifications for permission handling and deep linking
- Add expo-notifications dependency and configure with JPush plugin - Request notification permission on app launch for iOS/Android - Handle notification taps to navigate to chat or notifications screen - Add UI to check and request system notification permission in settings - Refactor background sync: WebSocket disconnects in background, JPush handles push - Add checkNotificationPermission() and requestNotificationPermission() to jpushService
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Platform, NativeModules } from 'react-native';
|
||||
import { pushService } from './pushService';
|
||||
import * as Notifications from 'expo-notifications';
|
||||
|
||||
type JPushNotificationMessage = {
|
||||
messageID: string;
|
||||
@@ -305,6 +306,35 @@ class JPushService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求通知权限(使用 expo-notifications,统一处理 iOS/Android)
|
||||
*/
|
||||
async requestNotificationPermission(): Promise<boolean> {
|
||||
if (Platform.OS === 'web') return false;
|
||||
|
||||
try {
|
||||
const { status } = await Notifications.requestPermissionsAsync();
|
||||
return status === 'granted';
|
||||
} catch (error) {
|
||||
console.warn('[JPush] request notification permission failed:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查通知权限是否已开启
|
||||
*/
|
||||
async checkNotificationPermission(): Promise<boolean> {
|
||||
if (Platform.OS === 'web') return false;
|
||||
|
||||
try {
|
||||
const { status } = await Notifications.getPermissionsAsync();
|
||||
return status === 'granted';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup(): void {
|
||||
this.isInitialized = false;
|
||||
this.registrationID = null;
|
||||
|
||||
Reference in New Issue
Block a user