# 为 Cordova 设置角标

由于 Cordova 插件不包含 `PWNotificationExtensionManager` 头文件，您必须执行几个额外步骤才能为您的 Cordova 项目实现角标。

要设置角标，请完成以下步骤：

1. 创建通知服务扩展 (Notification Service Extension)
2. 添加 Pushwoosh 框架
3. 添加 App Groups 功能

<Aside type="note">
要为 iOS 原生应用实现角标，请参阅[设置角标](/zh/developer/pushwoosh-sdk/ios-sdk/setting-up-badges/)指南。
</Aside>

### 1. 添加通知服务扩展 (Notification Service Extension) (File -> New -> Target...)

<img src="/shared-7.webp" alt=""/>

### 2. 选择 "Notification Service Extension"

<img src="/cordova-setting-up-badges-for-cordova-1.webp" alt=""/>

### 3. 如下所示，将 Pushwoosh.xcframework 添加到 NotificationService 扩展目标：

1. 选择 **NotificationService** 扩展目标。
2. 转到 “**General**” 选项卡。
3. 找到 “**Framework and Libraries**” 并按 “**+**” 按钮。
4. 选择 **Pushwoosh.xcframework**。

<img src="/shared-8.webp" alt=""/>

<img src="/shared-3.webp" alt=""/>

### 4. 如下所示，更新 Notification Service Extension 代码：

```
#import "NotificationService.h"
#import "PWNotificationExtensionManager.h"

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];

    [[PWNotificationExtensionManager sharedManager] handleNotificationRequest:request contentHandler:contentHandler];
}

- (void)serviceExtensionTimeWillExpire {
    // Called just before the extension will be terminated by the system.
    // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
    self.contentHandler(self.bestAttemptContent);
}

@end
```

### 5. 为应用的每个目标添加 "App Groups Capability"

<img src="/cordova-setting-up-badges-for-cordova-2.webp" alt=""/>

<img src="/cordova-setting-up-badges-for-cordova-3.webp" alt="App Groups 功能"/>

<img src="/cordova-setting-up-badges-for-cordova-4.webp" alt="Info.plist"/>

### 6. 将 App Groups ID 添加到应用的每个目标的 info.plist 中

```
<key>PW_APP_GROUPS_NAME</key>
<string>group.com.example.demoapp_example</string>
```

## 与我们分享您的反馈

您的反馈有助于我们创造更好的体验，因此如果您在 SDK 集成过程中遇到任何问题，我们很乐意听取您的意见。如果您遇到任何困难，请随时[通过此表单](https://docs.google.com/forms/d/e/1FAIpQLSd\_0b8jwn-V\_JmoPLIxIFYbHACCQhrzidOZV3ELywoQPXRSxw/viewform)与我们分享您的想法。