# การตั้งค่า badges สำหรับ Flutter

1. เปิดโปรเจกต์ iOS ของคุณที่อยู่ใน **your_project/ios/Runner.xcworkspace** และสร้าง **NotificationServiceExtension**:

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

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

2. เปิด Podfile (ที่อยู่ใน **your_project/ios/Podfile**) และเพิ่ม dependency **PushwooshXCFramework** สำหรับ NotificationServiceExtensionTarget:

```
target ‘NotificationService’ do
  pod ‘PushwooshXCFramework’, ‘>=6.5.0’
end
```

<Aside type="note">
คุณสามารถวางบรรทัดเหล่านี้หลัง `target ‘Runner’ do` ได้เหมือนในตัวอย่างด้านล่าง:

```bash title="ตัวอย่าง Podfile"
target ‘Runner’ do
  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end
target ‘NotificationService’ do
  pod ‘PushwooshXCFramework’, ‘>=6.5.0’
end
post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end
```
</Aside>

3. ติดตั้ง pods ผ่าน Terminal:

```
cd ios && pod install
```

4. ปิดและเปิดโปรเจกต์ Xcode ของคุณอีกครั้ง

<Aside type="caution">
ตรวจสอบให้แน่ใจว่าคุณเปิดโปรเจกต์ **ผ่าน .xcworkspace** และไม่ใช่ผ่าน .xcproject
</Aside>

5. ตรวจสอบให้แน่ใจว่า **Deployment target ของคุณตรงกับใน Runner target** มิฉะนั้นคุณอาจประสบปัญหาในการ build แอปของคุณ (เช่น หากคุณระบุ iOS 10.0 ใน Runner และ iOS 15.5 ใน NotificationService targets)

6. เพิ่ม **App Groups capability** ไปยังทั้ง Runner และ NotificationService targets และเพิ่ม group ใหม่ที่มีชื่อเดียวกันสำหรับทั้งสอง targets:

<img src="/flutter-setting-up-badges-for-flutter-3.webp" alt=""/>

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

7. เพิ่มแฟล็ก **PW_APP_GROUPS_NAME** info.plist ไปยังทั้ง Runner และ NotificationService targets โดยมีชื่อ group เป็นค่าสตริง:

<img src="/flutter-setting-up-badges-for-flutter-5.webp" alt=""/>

8. ไปที่ **NotificationService.m** และแทนที่โค้ดด้วยโค้ดต่อไปนี้:

```objective-c
#import “NotificationService.h”
#import &#x3C;Pushwoosh/PWNotificationExtensionManager.h>

@interface NotificationService ()
<strong>@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
</strong>@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
```


## แบ่งปันความคิดเห็นของคุณกับเรา

ความคิดเห็นของคุณช่วยให้เราสร้างประสบการณ์ที่ดีขึ้น เราจึงยินดีรับฟังหากคุณมีปัญหาใดๆ ในระหว่างขั้นตอนการผสานรวม SDK หากคุณประสบปัญหาใดๆ โปรดอย่าลังเลที่จะแบ่งปันความคิดของคุณกับเรา [ผ่านแบบฟอร์มนี้](https://docs.google.com/forms/d/e/1FAIpQLSd\_0b8jwn-V\_JmoPLIxIFYbHACCQhrzidOZV3ELywoQPXRSxw/viewform)