globocom / react-native-ua

React Native module for Urban Airship
MIT License
37 stars 33 forks source link

on_notification event not fires on iOS when app is closed & user clicks on interactive button #34

Open adamivancza opened 7 years ago

adamivancza commented 7 years ago

Hi @rlepinski ,

I've an issue with the on_notification event - it not fires if the following conditions are met:

FYI: it works fine if I just click on the notification - on_notification fires properly in this case.

I did some digging in the iOS code and I think the issue lies in either https://github.com/globocom/react-native-ua/blob/master/ios/ReactNativeUAIOS/ReactNativeUAIOS.m#L202

or here https://github.com/globocom/react-native-ua/blob/master/ios/ReactNativeUAIOS/ReactNativeUAIOS.m#L224

Could it be that in this case the notificationResponse.actionIdentifier is not UANotificationDefaultActionIdentifier?

rlepinski commented 7 years ago

So you have background notification actions. If its background the app will not launch, instead its suppose to be handled internally. I assume the react framework will not be ready to receive events if thats the case.

rlepinski commented 7 years ago

Actually it looks like a different event is fired https://github.com/globocom/react-native-ua/pull/35/files#diff-8df9edd5817d0f6fc4c5fadeebe5412dL213

adamivancza commented 7 years ago

So here is what I tried to achieve:

With my modification the following happens: 1) notificationResponse.actionIdentifier is more_info => event set to launchedFromNotification 2) it goes to handleNotification method which saves the notification 3) when JS code launches I can get the notification when I invoke the ReactNativeUA.handle_background_notification() method.

kulyk commented 7 years ago

For background processing:

Try sending push notifications with content-available: 1 param

Provide this key with a value of 1 to indicate that new content is available. Including this key and value means that when your app is launched in the background or resumed, application:didReceiveRemoteNotification:fetchCompletionHandler: is called.

If you use Urban Airship's Engage service, you can switch it on 'Delivery' page in iOS section. It is called 'Background Processing'.