react-native-fcm icon indicating copy to clipboard operation
react-native-fcm copied to clipboard

Action click push notifocation

Open ChanhTran255 opened this issue 8 years ago • 18 comments

I can't get action click push notification. I want get action click because after click will open url . Thank you.

My code.

` componentDidMount() { //console.log('wrapper did mount') NetInfo.addEventListener('change', this._handleConnectionInfoChange ); NetInfo.fetch().done ( (connectionInfo) => { this._handleConnectionInfoChange(connectionInfo); } );

//Config Push Notification
if(Platform.OS == 'ios') {
    FCM.requestPermissions()
    .then(e => {})
    .catch(() => {})
}
FCM.getFCMToken().then(token => {
    // console.log('token', token)
    if(token && token != undefined) {                
        this._saveDeviceToken(token)
    }
})
this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, (token) => {  
    // console.log('token refresh', token)          
    if(token && token != undefined) {
        this._saveDeviceToken(token)
    }                
})
FCM.getInitialNotification().then(notification => {
    if(notification && notification.opened_from_tray) {
        this._openUrl(this.state.url);
    }
});
this.notificationListener = FCM.on(FCMEvent.Notification, (notification) => {
    if(notification)
    {            
        const url_open = notification.url;
        this.setState({
            url: url_open ? url_open : false
        })
        if(notification.local_notification) { 
            if(notification.opened_from_tray) {
                this._openUrl(this.state.url);
            }
            return;
        }
        if(notification.opened_from_tray) {
            return;
        }
        const title = notification.fcm.title;
        FCM.presentLocalNotification({
            priority: 'high',
            title: title ? title : Params.Name,
            body: notification.fcm.body,
            big_text: notification.fcm.body,
            icon: 'pushicon',
            large_icon: 'joinmunch',
            url : url_open,
            lights: true,
            show_in_foreground: true,
            local: true
        })  
        FCM.cancelAllLocalNotifications()
    }
})

}`

ChanhTran255 avatar Nov 14 '17 03:11 ChanhTran255

this.setState({ url: url_open ? url_open : false }) sets states in next event loop. that might be your issue?

Does the callback get called?

evollu avatar Nov 17 '17 02:11 evollu

When get notification i save url. I want get action click notification.

ChanhTran255 avatar Nov 17 '17 03:11 ChanhTran255

sorry I don't quite understand what you want

evollu avatar Nov 17 '17 03:11 evollu

When you get a notification, when you touch it, it will open the app for you. I want to catch the event when you touch it. Previously, I could use get action to click. But current i can't.

FCM.getInitialNotification().then(notification => { if(notification && notification.opened_from_tray) { this._openUrl(this.state.url); } });

ChanhTran255 avatar Nov 17 '17 03:11 ChanhTran255

why currently you can't? someone opened an issue that notification.opened_from_tray is undefined in getInitialNotification

evollu avatar Nov 17 '17 03:11 evollu

Previously after touch notification it will go to getInitialNotification. Current i don't see.

ChanhTran255 avatar Nov 17 '17 03:11 ChanhTran255

My Code

componentDidMount() { //console.log('wrapper did mount') NetInfo.addEventListener('change', this._handleConnectionInfoChange ); NetInfo.fetch().done ( (connectionInfo) => { this._handleConnectionInfoChange(connectionInfo); } );

    //Config Push Notification
    if(Platform.OS == 'ios') {
        FCM.requestPermissions()
        .then(e => {})
        .catch(() => {})
    }
    
    FCM.getFCMToken().then(token => {
        if(token && token != undefined) {                
            this._saveDeviceToken(token)
        }
    })

    this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, (token) => {  
        if(token && token != undefined) {
            this._saveDeviceToken(token)
        }                
    })

    FCM.getInitialNotification().then(notification => {
        if(notification && notification.opened_from_tray) {
            this._openUrl(this.state.url);
        }
    });
    this.notificationListener = FCM.on(FCMEvent.Notification, (notification) => {
        if(notification)
        {            
            const url_open = notification.url;
            this.setState({
                url: url_open ? url_open : false
            })
            if(notification.local_notification) { 
                if(notification.opened_from_tray) {
                    this._openUrl(this.state.url);
                }
                return;
            }
            if(notification.opened_from_tray) {
                return;
            }
            const title = notification.fcm.title;
            FCM.presentLocalNotification({
                priority: 'high',
                title: title ? title : Params.Name,
                body: notification.fcm.body,
                big_text: notification.fcm.body,
                icon: 'pushicon',
                large_icon: 'joinmunch',
                url : url_open,
                lights: true,
                show_in_foreground: true,
                local: true
            })  
            FCM.cancelAllLocalNotifications()
        }
    })
}

ChanhTran255 avatar Nov 17 '17 03:11 ChanhTran255

I haven't changed any behavior recently. don't you see it in FCM.on(FCMEvent.Notification?

evollu avatar Nov 17 '17 04:11 evollu

yes. when click i don't see any one event in FCM.on(FCMEvent.Notification

ChanhTran255 avatar Nov 17 '17 04:11 ChanhTran255

so you are saying when you tap on notification you don't see any callback in javascript? How about moving the listeners out of component lifecycle?

evollu avatar Nov 17 '17 17:11 evollu

Previously my code same now. It still working when tab on notification but current it not wroking.

ChanhTran255 avatar Nov 22 '17 09:11 ChanhTran255

Hi @evollu, I'm having the same problem. When notification received, I can log it from notification listener. When I click the notification,it show FCM without any other data

fcm android on click

Any idea to solve this issue?

addingama avatar Nov 28 '17 07:11 addingama

@dashracer let me check

evollu avatar Nov 29 '17 16:11 evollu

wait. what OS are you using? iOS? Can't do much for iOS and that's all the system gives me. Duplicated the value in data

evollu avatar Nov 29 '17 16:11 evollu

@evollu Those screenshot from android

addingama avatar Nov 29 '17 23:11 addingama

I don't have such issue with the example project in android screenshot_1511974589

evollu avatar Nov 30 '17 03:11 evollu

I am also facing the same issue as @ChanhTran255. I didn't get the data when i click on notification.

DikshaDeep avatar May 29 '18 11:05 DikshaDeep

I also want an event when notification is clicked. I want to navigate to particular screen when notification is pressed. Any Solution?

rohit75 avatar May 06 '19 04:05 rohit75