根据提供的 git diff,我来分析这次变更:
## 变更分析 这次提交主要涉及 APNs 推送通知功能的优化: 1. **apns.provider.ts** 的变更: - 重构了通知选项的构建逻辑,将 alert 设置为顶层属性 - 增强了 `createDeviceNotification` 方法,完整复制所有通知选项(badge、sound、contentAvailable、mutableContent、priority、type、data) - 移除了未使用的 aps 对象 2. **push-notifications.service.ts** 的变更: - 移除了冗余的 `alert` 字段 - 新增了更多 APNs 通知选项:priority、expiry、collapseId、mutableContent、contentAvailable 这是一次功能增强和代码重构,主要目的是完善 APNs 推送通知的配置选项支持。 ## 建议的提交信息 feat(push-notifications): 完善APNs推送通知配置选项支持 - 重构通知选项构建逻辑,优化alert属性设置 - createDeviceNotification方法新增完整选项复制(badge、sound、contentAvailable、mutableContent、priority、type、data) - 推送服务新增priority、expiry、collapseId、mutableContent、contentAvailable等配置项支持 - 移除冗余的alert字段设置
This commit is contained in:
@@ -241,8 +241,16 @@ export class ApnsProvider implements OnModuleInit, OnModuleDestroy {
|
|||||||
// 构建通知选项
|
// 构建通知选项
|
||||||
const notificationOptions: any = {};
|
const notificationOptions: any = {};
|
||||||
|
|
||||||
// 设置 APS 属性
|
// 设置 alert 属性 - 这是必需的
|
||||||
const aps: any = {};
|
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) {
|
if (options.badge !== undefined) {
|
||||||
notificationOptions.badge = options.badge;
|
notificationOptions.badge = options.badge;
|
||||||
@@ -333,9 +341,43 @@ export class ApnsProvider implements OnModuleInit, OnModuleDestroy {
|
|||||||
*/
|
*/
|
||||||
private createDeviceNotification(notification: Notification, deviceToken: string): Notification {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -677,14 +677,18 @@ export class PushNotificationsService {
|
|||||||
|
|
||||||
// 创建APNs通知
|
// 创建APNs通知
|
||||||
const apnsNotification = this.apnsProvider.createNotification({
|
const apnsNotification = this.apnsProvider.createNotification({
|
||||||
alert: notificationData.title,
|
|
||||||
title: notificationData.title,
|
title: notificationData.title,
|
||||||
body: notificationData.body,
|
body: notificationData.body,
|
||||||
data: notificationData.payload,
|
data: notificationData.payload,
|
||||||
pushType: notificationData.pushType,
|
pushType: notificationData.pushType,
|
||||||
|
priority: notificationData.priority,
|
||||||
|
expiry: notificationData.expiry,
|
||||||
|
collapseId: notificationData.collapseId,
|
||||||
topic: this.bundleId,
|
topic: this.bundleId,
|
||||||
sound: notificationData.sound,
|
sound: notificationData.sound,
|
||||||
badge: notificationData.badge,
|
badge: notificationData.badge,
|
||||||
|
mutableContent: notificationData.mutableContent,
|
||||||
|
contentAvailable: notificationData.contentAvailable,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logger.log(`apnsNotification: ${JSON.stringify(apnsNotification, null, 2)}`);
|
this.logger.log(`apnsNotification: ${JSON.stringify(apnsNotification, null, 2)}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user