Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[firebase_messaging] Should support Rich notifications by default on iOS. #357

Closed
kroikie opened this issue Oct 13, 2019 · 14 comments
Closed
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) plugin: messaging type: enhancement New feature or request

Comments

@kroikie
Copy link
Collaborator

kroikie commented Oct 13, 2019

It still does not support Rich Notifications (Notifications with Image) on iOS, Anybody has workaround for this??? If not this would be a feature request.

@kroikie
Copy link
Collaborator Author

kroikie commented Oct 13, 2019

@kaumudpa

The issue at flutter/flutter#35866 has been closed and moved here. Future collaboration on this issue will be done here.

@kaumudpa
Copy link

Do we have any updates on this one?

@kroikie
Copy link
Collaborator Author

kroikie commented Nov 13, 2019

@kaumudpa we are currently working on getting FCM on iOS stable. Adding support for rich notifications is on our roadmap, thanks for pinging this issue.

@LOG-TAG
Copy link

LOG-TAG commented Feb 22, 2020

Any update or custom solution on this?

@LOG-TAG
Copy link

LOG-TAG commented Feb 22, 2020

any service class or any fix available via https://docs.mobile.sailthru.com/docs/ios-extensions-framework CarnivalNotificationServiceExtension?

@LOG-TAG
Copy link

LOG-TAG commented Mar 8, 2020

@kroikie any early access solutions available?

@p30arena
Copy link
Contributor

p30arena commented Apr 1, 2020

@kroikie @iapicca
I'm curious how the plugin handles images on the Android side.
Can this PR #2016 somehow help this issue?

@Ehesp Ehesp added plugin: messaging impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) labels Apr 20, 2020
@kaumudpa

This comment has been minimized.

@LOG-TAG
Copy link

LOG-TAG commented May 4, 2020

@p30arena this is to deal with ios Rich notification extension, flutter SDK should call ios-extensions-framework @tobiasjunsten any work arround is possible ?

@binhnt13682104
Copy link

binhnt13682104 commented Jun 4, 2020

#import "NotificationService.h"

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
@property (nonatomic, strong) NSURLSessionDownloadTask *downloadTask;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];
    
    // Modify the notification content here...
    [self sailthruRichNotificationAttachments:self.bestAttemptContent withResponse:^(UNMutableNotificationContent * _Nullable content) {
        self.bestAttemptContent = content;
        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.downloadTask cancel];
    
    self.contentHandler(self.bestAttemptContent);
}

- (void)sailthruRichNotificationAttachments:(UNMutableNotificationContent *)originalContent withResponse:(nullable void(^)(UNMutableNotificationContent *__nullable modifiedContent))block  {
    // For Image or Video in-app messages, we will send the media URL in the
    // _st payload
    NSString *imageURL = originalContent.userInfo[@"fcm_options"][@"image"];
    NSString *videoURL = originalContent.userInfo[@"fcm_options"][@"video"];
    
    NSURL *attachmentURL = nil;
    if (videoURL && ![videoURL isKindOfClass:[NSNull class]]) { //Prioritize videos over image
        attachmentURL = [NSURL URLWithString:videoURL];
    }
    else if (imageURL && ![imageURL isKindOfClass:[NSNull class]]) {
        attachmentURL = [NSURL URLWithString:imageURL];
    }
    else {
        block(originalContent); //Nothing to add to the push, return early.
        return;
    }
    
    NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    self.downloadTask = [session downloadTaskWithURL:attachmentURL completionHandler:^(NSURL *fileLocation, NSURLResponse *response, NSError *error) {
        if (error != nil) {
            block(originalContent); //Nothing to add to the push, return early.
            return;
        }
        else {
            NSFileManager *fileManager = [NSFileManager defaultManager];
            NSString *fileSuffix = attachmentURL.lastPathComponent;
            
            NSURL *typedAttachmentURL = [NSURL fileURLWithPath:[(NSString *_Nonnull)fileLocation.path stringByAppendingString:fileSuffix]];
            [fileManager moveItemAtURL:fileLocation toURL:typedAttachmentURL error:&error];
            
            NSError *attachError = nil;
            UNNotificationAttachment *attachment = [UNNotificationAttachment attachmentWithIdentifier:@"" URL:typedAttachmentURL options:nil error:&attachError];
            
            if (attachment == nil) {
                block(originalContent); //Nothing to add to the push, return early.
                return;
            }
            
            UNMutableNotificationContent *modifiedContent = originalContent.mutableCopy;
            [modifiedContent setAttachments:[NSArray arrayWithObject:attachment]];
            block(modifiedContent);
        }
    }];
    [self.downloadTask resume];
}

@end

note: change this flow your notification model:
My notification I received is:

{fcm_options: {image: https://file.hstatic.net/1000187248/file/noi_bat_b65bf35c4bbf49f19315f758a4a15e02.jpg}, gcm.message_id: 1591237257298321, google.c.a.e: 1, aps: {alert: {title: test, body: test notification image}, mutable-content: 1.0}}

=> so:

NSString *imageURL = originalContent.userInfo[@"fcm_options"][@"image"]; 
NSString *videoURL = originalContent.userInfo[@"fcm_options"][@"video"];
  • If error about bitcode: open target NotificationService, tab Build Settings, find bitcode -> select No

Screen Shot 2020-06-04 at 22 13 01

=> Done

image

@diegoveloper

This comment has been minimized.

@diegoveloper
Copy link
Contributor

Any news about this :) ?

@chandrashan
Copy link

doing a photography based app and it would be great to have this functionality for iOS

@Salakar
Copy link
Member

Salakar commented Nov 4, 2020

Hey all 👋

As part of our roadmap (#2582) we've just shipped a complete rework of the firebase_messaging plugin that aims to solve this and many other issues. Specifically see the Notifications with images documentation: https://firebase.flutter.dev/docs/messaging/apple-integration/#advanced-optional-allowing-notification-images

If you can, please try out the dev release (see the migration guide for upgrading and for changes) and if you have any feedback then join in the discussion here.

Given the scope of the rework I'm going to go ahead and close this issue in favor of trying out the latest plugin.

Thanks everyone 🤓

@Salakar Salakar closed this as completed Nov 4, 2020
@firebase firebase locked and limited conversation to collaborators Dec 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) plugin: messaging type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

10 participants