跳到内容

为 Flutter 设置角标

  1. 打开位于 your_project/ios/Runner.xcworkspace 的 iOS 项目并创建 NotificationServiceExtension
  1. 打开 Podfile(位于 your_project/ios/Podfile)并为 NotificationServiceExtensionTarget 添加 PushwooshXCFramework 依赖项:
target ‘NotificationService’ do
pod ‘PushwooshXCFramework’, ‘>=6.5.0’
end
  1. 通过 Terminal 安装 pods:
cd ios && pod install
  1. 关闭并重新打开您的 Xcode 项目。
  1. 确保您的 Deployment targetRunner target 中的目标相匹配;否则,您在构建应用程序时可能会遇到问题(例如,如果您在 Runner 目标中指定 iOS 10.0,而在 NotificationService 目标中指定 iOS 15.5)。

  2. App Groups capability 添加到 Runner 和 NotificationService 目标,并为这两个目标添加一个同名的新组:

  1. PW_APP_GROUPS_NAME info.plist 标志添加到 Runner 和 NotificationService 目标,并以组名作为其字符串值:
  1. 前往 NotificationService.m 并将其代码替换为以下内容:
#import “NotificationService.h”
#import <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

大功告成!

与我们分享您的反馈

Anchor link to

您的反馈有助于我们创造更好的体验,因此如果您在 SDK 集成过程中遇到任何问题,我们非常希望听到您的声音。如果您遇到任何困难,请随时通过此表单与我们分享您的想法。