コンテンツにスキップ

RichFlyerからの通知を判別

RichFlyerから配信されたプッシュ通知とそれ以外から配信されたプッシュ通知を判別できます。

判別方法

// Class RFApp
static func isRichFlyerNotification(userInfo: [AnyHashable : Any]) -> Bool
// Class RFApp
+ isRichFlyerNotification:
パラメータ 内容
userInfo UNNotificationContent.userInfo


実装例

Swift

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 {
            if (RFApp.isRichFlyerNotification(userInfo: bestAttemptContent.userInfo)) {
                // RichFlyerで配信したプッシュ通知
                RFNotificationService.configureRFNotification(content: bestAttemptContent,
                                                            appGroupId: "group.net.richflyer.app",
                                                            displayNavigate: true,
                                                            completeHandler: { (content) in
                    contentHandler(content)
                })

            } else {
                // RichFlyer以外でで配信したプッシュ通知
                contentHandler(bestAttemptContent)
            }
        }
    }
}

Objective-C

@implementation NotificationService

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

    if ([RFApp isRichFlyerNotification:self.bestAttemptContent.userInfo]) {
        // RichFlyerで配信したプッシュ通知
        [RFNotificationService configureRFNotification:self.bestAttemptContent
                                appGroupId:@"group.net.richflyer.app"
                                displayNavigate:YES
                                completeHandler:^(UNMutableNotificationContent *content) {

        self.bestAttemptContent = content;
        self.contentHandler(self.bestAttemptContent);      
        }];
    } else {
        // RichFlyer以外で配信したプッシュ通知
        self.contentHandler(self.bestAttemptContent);
    }    
}

@end