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

Unable to add an attachment to ios notification #939

Closed
judemanutd opened this issue Apr 6, 2018 · 17 comments
Closed

Unable to add an attachment to ios notification #939

judemanutd opened this issue Apr 6, 2018 · 17 comments

Comments

@judemanutd
Copy link
Contributor

judemanutd commented Apr 6, 2018

Issue

Environment

  1. Application Target Platform: iOS
  2. Development Operating System: Windows 10
  3. Build Tools: Xcode 9
  4. React Native version: 0.54.3
  5. RNFirebase Version: 4.0.0
  6. Firebase Module: Notification

I have used the react native fetch blob library to download an image using the url. I am then supplying the image to the attachment but nothing shows up in the attachment.

The notification shows up fine with the title and body but there is no attachment.

const notification = new firebase.notifications.Notification()
.setNotificationId('notificationId')
.setTitle('My notification title')
.setBody('My notification body')
.ios.addAttachment('1',res.path());

res.path() gives me the path of the image locally downloaded.

@chrisbianca
Copy link
Contributor

Thanks for the report, we'll investigate.

@judemanutd
Copy link
Contributor Author

judemanutd commented Apr 9, 2018

@chrisbianca Same issue on android, unable to get big picture to work
Using the following code

function createNotification(alert) {


    let notification = new firebase.notifications.Notification()
        .setNotificationId(JSON.stringify(alert['id']))
        .setTitle(alert['title'])
        .setBody((alert['description']));

    const channel = new firebase.notifications.Android.Channel('breaking_news', 'Breaking News', firebase.notifications.Android.Importance.Max)
        .setDescription('Breaking News channel');

    firebase.notifications().android.createChannel(channel);

    console.log("image url = " + fetchyouTubeVideoThumbnail('Qv6p6pTz5I'));

    RNFetchBlob
        .config({
            fileCache: true,
            appendExt: fetchExtension(fetchyouTubeVideoThumbnail('Qv6p6pTz5I'))
        })
        .fetch('GET', fetchyouTubeVideoThumbnail('Qv6p6pTz5I'))
        .then((res) => {

            console.log(`File = file://${res.path()}`);

            notification
                .android.setBigPicture(`file://${res.path()}`, 'ic_launcher', alert['title'], alert['description'])
                .android.setSmallIcon('ic_launcher_notification_icon')
                .android.setAutoCancel(true)
                .android.setChannelId('breaking_news')
                .android.setSmallIcon('ic_launcher');

            firebase.notifications().displayNotification(notification)

        })
        .catch((error) => {
            console.log("Error downloading " + error);
        });
}

The docs say that the picture parameter needs to be supplied The bitmap to be used as the payload for the BigPicture notification.

The data i get from res.path() is /data/user/0/com.example/files/RNFetchBlobTmp_k82h0qbvdxjjj4a71f0fd.jpg is that the correct way or should I be giving file:///data/user/0/com.example/files/RNFetchBlobTmp_z5d5qibnrglyzqwqoymo.jpg or something else?

@judemanutd
Copy link
Contributor Author

Managed to get image working in android, the doc currently does not give alot of information about the type of data that needs to be given for the picture parameter.

For those looking it needs an http or https link or a filename that points to a mipmap resource in the android res directory.

I have created a PR to add the necessary info to the docs.

@chrisbianca
Copy link
Contributor

@judemanutd RE: Android. I've just pushed up a change which should support file:// urls. This will be released as part of v4.0.1 shortly. Would you be able to verify if this is the case?

RE: iOS. I will investigate as part of v4.0.2

@judemanutd
Copy link
Contributor Author

@chrisbianca Yes I can verify the change once its live. Looking forward to the issue being sorted with iOS too, are there any hardware requirements for the iOS notification with an image to show? 3D touch ? Higher screen resolution ?

@chrisbianca
Copy link
Contributor

@judemanutd v4.0.1 is available now. I'm not sure on the iOS notification to be honest, I'll have some time to look into it later this week.

@judemanutd
Copy link
Contributor Author

@chrisbianca would it be possible to provide an example usage for adding an attachment in iOS for a notification, maybe an example y'all used during development which i could test.

@judemanutd
Copy link
Contributor Author

@chrisbianca Using 4.0.1 but unable to get image in notification using file:// url.

 _createNotif = () => {
        let dirs = RNFetchBlob.fs.dirs;
        RNFetchBlob.config({
            path: dirs.DownloadDir + '/testing.jpg'
        }).fetch('GET', "https://img.youtube.com/vi/YjMSttRJrhA/0.jpg")
            .then((res) => {

                console.log("File url = ", `file://${res.path()}`);

                let notification = new firebase.notifications.Notification()
                    .setNotificationId('12')
                    .setTitle('title')
                    .setBody('description')
                    .android.setChannelId('test_channel')
                    .android.setBigPicture(`file://${res.path()}`)
                    .setData({
                        key: true,
                        key2: false
                    });

                const channel = new firebase.notifications.Android.Channel('test_channel', 'Test Channel', firebase.notifications.Android.Importance.Max)
                    .setDescription('Testing channel');

                firebase.notifications().android.createChannel(channel).then(() => {
                    firebase.notifications().displayNotification(notification);
                });

            });

    };

This produces a file url file:///storage/emulated/0/Download/testing.jpg

screenshot_1523383909

Testing on Android 7.1.1 API 25

P.S. I think we need to shift this to a separate thread rather than hijacking the ios issue.

@chrisbianca
Copy link
Contributor

This is now fixed, pending release of v4.0.3

@MrLoh
Copy link
Contributor

MrLoh commented Jun 16, 2018

@judemanutd @chrisbianca

Is there an example how to get this to work on iOS? There seems to be a lack of examples for these advanced topics. What exactly does the URL have to look like that I pass to addAttachement? My current setup is something like this:

const res = await RNFetchBlob
  .config({ fileCache: true, appendExt: 'jpg' })
  .fetch('GET', 'https://static.cinuru.com/public/backdropSmall/1524495663496.jpg');
notification.ios.addAttachment('1', `file://${res.path()}`);

The created path looks like this:
file:///var/mobile/Containers/Data/Application/4396DF40-11CF-4925-A700-00DD33277512/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_h29pji7jzgejuk46y5pcei.jpg

@judemanutd
Copy link
Contributor Author

@MrLoh just ${res.path()} is fine for iOS, you need file://${res.path()} if you're using android

@MrLoh
Copy link
Contributor

MrLoh commented Jun 18, 2018

awesoe, that did the trick. I thought I had tried all combinations, clearly I didn't.

@tuvshinbatgeru
Copy link

Just let me know guys @MrLoh @judemanutd . Attached file must be local file or it is work with external url as well?

@MrLoh
Copy link
Contributor

MrLoh commented Aug 24, 2018

@Akillis must be downloaded locally first with something like RNFetchBlob.

@venux92
Copy link

venux92 commented Nov 5, 2018

How does it works when the app is in the background or close?
I had it to work in foreground but as soon as the app is in the background or killed I only have the text no more image.
Any ideas?

@venux92
Copy link

venux92 commented Nov 6, 2018

@MrLoh Great thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants