コンテンツにスキップ

通知バッジの設定(iOS)

RichFlyerではプッシュ通知を受信直後は、通知センターに残っている未読の件数がバッチに表示されます。
アプリを起動後は、以下の方法で端末のホーム画面のアプリアイコンに表示するバッジを非表示設定にできます。


バッジの非表示

// RichflyerSdkFlutterクラス
Future<void> resetBadgeNumber()

本メソッドを実行した場合、iOSアプリのみで動作します。。Androidアプリでは動作しません。


実装例

Dart
void initState() {
    super.initState();

    // バッジを非表示にする
    RichflyerSdkFlutter().resetBadgeNumber();
}


プッシュ通知受信直後のバッジの値を変更したい場合

プッシュ通知受信直後に、通知センターの未読件数ではなく、任意の値を表示したい場合はXcodeプロジェクトを開きNotification Service Extensionに以下のように実装してください。

Swift

NotificationService.swift

import UserNotifications
import RichFlyer

class NotificationService: UNNotificationServiceExtension {

    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?

    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

        if let bestAttemptContent = bestAttemptContent {
            // Modify the notification content here...
            RFNotificationService.configureRFNotification(content: bestAttemptContent,
                                    appGroupId: "group.jp.co.infocity.richflyer",
                                    displayNavigate: true,
                                    completeHandler: { (content) in

                content.badge = NSNumber(value: 1)
                contentHandler(content)
            })
        }
    }

    override func 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.
        if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
            contentHandler(bestAttemptContent)
        }
    }
}
Objective-C

NotificationService.m

#import "NotificationService.h"
#import <RichFlyer/RichFlyer.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];

    [RFNotificationService configureRFNotification:self.bestAttemptContent
                            appGroupId:@"group.jp.co.infocity.richflyer"
                            displayNavigate:YES
                            completeHandler:^(UNMutableNotificationContent *content) {
        self.bestAttemptContent = content;
        // バッジの値を1にする
        self.bestAttemptContent.badge = [NSNumber numberWithInt:1];
        self.contentHandler(self.bestAttemptContent);
    }];
}

- (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