ข้ามไปยังเนื้อหา

การตั้งค่า Badges สำหรับ Cordova

เนื่องจากปลั๊กอิน Cordova ไม่มีเฮดเดอร์ PWNotificationExtensionManager คุณจึงต้องทำขั้นตอนเพิ่มเติมหลายอย่างเพื่อติดตั้ง Badges สำหรับโปรเจกต์ Cordova ของคุณ

สิ่งที่คุณต้องทำเพื่อตั้งค่า Badges มีดังนี้:

  1. สร้าง Notification Service Extension
  2. เพิ่มเฟรมเวิร์ก Pushwoosh
  3. เพิ่มความสามารถ App Groups

1. เพิ่ม Notification Service Extension (File -> New -> Target…)

Anchor link to

2. เลือก “Notification Service Extension”

Anchor link to

3. เพิ่ม Pushwoosh.xcframework ไปยัง target ของ NotificationService extension ดังนี้:

Anchor link to
  1. เลือก target ของ NotificationService extension
  2. ไปที่แท็บ “General
  3. ค้นหา ‘Framework and Libraries’ แล้วกดปุ่ม ’+
  4. เลือก Pushwoosh.xcframework

4. อัปเดตโค้ดของ Notification Service Extension ดังนี้:

Anchor link to
#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” สำหรับแต่ละ target ของแอปพลิเคชันของคุณ

Anchor link to
App Groups CapabilityInfo.plist

6. เพิ่ม App Groups ID ไปยังไฟล์ info.plist ของคุณสำหรับแต่ละ target ของแอปพลิเคชัน

Anchor link to
<key>PW_APP_GROUPS_NAME</key>
<string>group.com.example.demoapp_example</string>

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

Anchor link to

ความคิดเห็นของคุณช่วยให้เราสร้างประสบการณ์ที่ดีขึ้น เราจึงยินดีรับฟังความคิดเห็นของคุณหากคุณพบปัญหาระหว่างขั้นตอนการติดตั้ง SDK หากคุณประสบปัญหาใดๆ โปรดอย่าลังเลที่จะแบ่งปันความคิดเห็นของคุณกับเรา ผ่านแบบฟอร์มนี้