feat(push): 新增iOS APNs推送通知功能
- 添加推送通知管理器和设备令牌管理 - 实现推送通知权限请求和令牌注册 - 新增推送通知设置页面 - 集成推送通知初始化到应用启动流程 - 添加推送通知API服务和本地存储管理 - 更新个人页面添加推送通知设置入口
This commit is contained in:
@@ -2,6 +2,7 @@ import { ROUTES } from '@/constants/Routes';
|
||||
import { getNotificationEnabled } from '@/utils/userPreferences';
|
||||
import * as Notifications from 'expo-notifications';
|
||||
import { router } from 'expo-router';
|
||||
import { pushNotificationManager } from './pushNotificationManager';
|
||||
|
||||
// 配置通知处理方式
|
||||
Notifications.setNotificationHandler({
|
||||
@@ -77,6 +78,24 @@ export class NotificationService {
|
||||
|
||||
try {
|
||||
this.isIniting = true
|
||||
|
||||
// 初始化推送通知管理器(包含设备令牌管理)
|
||||
const pushManagerInitialized = await pushNotificationManager.initialize({
|
||||
onTokenReceived: (token) => {
|
||||
console.log('设备令牌已接收:', token.substring(0, 20) + '...');
|
||||
},
|
||||
onTokenRefresh: (token) => {
|
||||
console.log('设备令牌已刷新:', token.substring(0, 20) + '...');
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error('推送通知管理器错误:', error);
|
||||
}
|
||||
});
|
||||
|
||||
if (!pushManagerInitialized) {
|
||||
console.warn('推送通知管理器初始化失败,但本地通知功能仍可用');
|
||||
}
|
||||
|
||||
// 请求通知权限
|
||||
const { status: existingStatus } = await Notifications.getPermissionsAsync();
|
||||
let finalStatus = existingStatus;
|
||||
@@ -91,7 +110,6 @@ export class NotificationService {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 设置通知监听器
|
||||
this.setupNotificationListeners();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user