diff --git a/src/push-notifications/apns.provider.ts b/src/push-notifications/apns.provider.ts index f9c9533..e162169 100644 --- a/src/push-notifications/apns.provider.ts +++ b/src/push-notifications/apns.provider.ts @@ -241,8 +241,16 @@ export class ApnsProvider implements OnModuleInit, OnModuleDestroy { // 构建通知选项 const notificationOptions: any = {}; - // 设置 APS 属性 - const aps: any = {}; + // 设置 alert 属性 - 这是必需的 + if (options.title || options.body) { + notificationOptions.alert = { + title: options.title || '', + body: options.body || '' + }; + } else if (options.alert) { + // 如果直接提供了 alert,使用它 + notificationOptions.alert = options.alert; + } if (options.badge !== undefined) { notificationOptions.badge = options.badge; @@ -333,9 +341,43 @@ export class ApnsProvider implements OnModuleInit, OnModuleDestroy { */ private createDeviceNotification(notification: Notification, deviceToken: string): Notification { // 创建新的通知实例,使用相同的选项但不同的设备令牌 - return new Notification(deviceToken, { - alert: notification.options.alert, - }); + // 复制所有通知选项 + const options: any = {}; + + if (notification.options.alert) { + options.alert = notification.options.alert; + } + + if (notification.options.badge !== undefined) { + options.badge = notification.options.badge; + } + + if (notification.options.sound) { + options.sound = notification.options.sound; + } + + if (notification.options.contentAvailable) { + options.contentAvailable = notification.options.contentAvailable; + } + + if (notification.options.mutableContent) { + options.mutableContent = notification.options.mutableContent; + } + + if (notification.options.priority) { + options.priority = notification.options.priority; + } + + if (notification.options.type) { + options.type = notification.options.type; + } + + // 复制自定义数据 + if (notification.options.data) { + options.data = notification.options.data; + } + + return new Notification(deviceToken, options); } /** diff --git a/src/push-notifications/push-notifications.service.ts b/src/push-notifications/push-notifications.service.ts index b4b8e22..a794708 100644 --- a/src/push-notifications/push-notifications.service.ts +++ b/src/push-notifications/push-notifications.service.ts @@ -677,14 +677,18 @@ export class PushNotificationsService { // 创建APNs通知 const apnsNotification = this.apnsProvider.createNotification({ - alert: notificationData.title, title: notificationData.title, body: notificationData.body, data: notificationData.payload, pushType: notificationData.pushType, + priority: notificationData.priority, + expiry: notificationData.expiry, + collapseId: notificationData.collapseId, topic: this.bundleId, sound: notificationData.sound, badge: notificationData.badge, + mutableContent: notificationData.mutableContent, + contentAvailable: notificationData.contentAvailable, }); this.logger.log(`apnsNotification: ${JSON.stringify(apnsNotification, null, 2)}`);