Comments (12)
There was a problem with intent handling and splash screens etc in the react-native-firebase repo, resolved with some specific steps in AndroidManifest to make the intent go to the right place crazycodeboy/react-native-splash-screen#289 (comment) - no idea at all if this applies here but if someone could confirm that they definitely don't have splash screens eating the launch intent, that might help.
from react-native-notifee.
Same here, can't get getInitialNotification to return anything other than null in dev mode.
Everything else seems to work just fine, including background and foreground notifications but this here is a blocker for my company right now.
useEffect(() => {
messaging()
.registerForRemoteNotifications()
.then(r => {
const granted = messaging().requestPermission();
messaging().subscribeToTopic('developers');
if (granted) {
notifee
.getInitialNotification()
.then(initial => {
if (initial) {
console.log('Initial');
console.log(initial);
} else {
console.log('no initial notification');
}
})
.catch(e => console.log(e));
}
});
}, []);
from react-native-notifee.
Same problem for me, i can't buying the package if this feature is not working.
Trying to get the initial notification from remote (firebase Messaging) and always return null if i open app from notification when app is killed.
Worste, if app is in background (not killed), i can't reach the event getInitialNotification().
- React-Native 61.5 (full hook, stateless)
- Hermes
- Tested with a real device connected (samsung s8+) in debug mode
from react-native-notifee.
Hey all
Thanks for the feedback - @mikehardy we actually implemented the initial notifications totally different to RNFB :D
Can you guys please show what notification options you're using to display the notification? When a pressAction
is provided to the body/actions, and that press action causes an open of the app, that's when we save the notification into it's initial state, hence knowing the options would help massively :)
We'll be sorting this as priority so don't worry!
from react-native-notifee.
Also it's worth mentioning (does mention in the docs but maybe not obvious enough?), that once a call to getInitialNotification
is called it is then cleared, so if there's a "double" mount/call that could be a problem.
Also @ja-bravo based on your code snippet, there is a couple of general issues:
getInitialNotification
has no impact on whether they're registered for notification or have them granted.- You have nested promises, and some calls which do not wait for promises so your code may not be even working as expected. A better example would be:
function App() {
async function bootstrap() {
const initialNotification = await notifee.getInitialNotification();
if (initialNotification) {
// Do something
}
await messaging().registerForRemoteNotifications();
const granted = await messaging().requestPermission();
await messaging().subscribeToTopic("developers");
// etc
}
useEffect(() => {
bootstrap().catch(e => console.error(e));
}, []);
}
In your example, granted
will always be true
because you're not waiting for the result, so granted
= Promise
, which is a truthy value :)
from react-native-notifee.
Hey all
Thanks for the feedback - @mikehardy we actually implemented the initial notifications totally different to RNFB :D
Can you guys please show what notification options you're using to display the notification? When a
pressAction
is provided to the body/actions, and that press action causes an open of the app, that's when we save the notification into it's initial state, hence knowing the options would help massively :)We'll be sorting this as priority so don't worry!
I'ts not a local notification but a remote.
I have no pressAction
option, just clicking on the notification.
If it can help, yes i'm using react-native-splash-screen
.
Json notification exemple:
{
"message": {
"token": "XXXXX",
"data": {
"type": "newComment",
"photoID": "XXXXX",
"fromUserID": "XXXXX"
},
"notification": {
"title": "Jhon commented your BeReal",
"body": "test"
},
"apns": {
"headers": {
"apns-priority": "5"
},
"payload": {
"aps": {
"thread-id": "XXXXX"
}
}
},
"android": {
"priority": "normal",
"notification": {
"channel_id": "default",
"icon": "ic_notification"
}
},
"fcm_options": {
"analytics_label": "newComment"
}
}
}
from react-native-notifee.
Conscious there could be different situations going on here...
@kperreau Notifee only manages it's own notifications, not those which have been created via the notification
payload, which the system creates automatically. If you check out the FCM guide it suggests to send the data over via the FCM payload and construct the notification manually (allowing for Notifee functionality to exist).
That being said, in theory we could also hook into "external" notifications and also manage them (e.g. checking for actions, providing default "press" behaviour).
from react-native-notifee.
Thanks for the answer @Ehesp. I copy-pasted that from the RNFB messaging documentation without double-checking, my bad.
We still can't get it to work on our app. We're not using react-native-splash-screen.
const AppContent = () => {
async function bootstrap() {
const initialNotification = await notifee.getInitialNotification();
if (initialNotification) {
console.log('initial notification'); // Never reaches here
console.log(initialNotification);
}
await messaging().registerForRemoteNotifications();
const granted = await messaging().requestPermission();
console.log(`granted: ${granted}`); // Logs granted: true
if (granted) {
await messaging().subscribeToTopic('developers');
console.log('sub to developers');
messaging().onMessage(onMessageReceived); // Works perfectly, we can display the notification using notifee
}
}
useEffect(() => {
console.log('Run bootstrap');
bootstrap().catch(e => console.log(e)); // No error gets logged
}, []);
return (
<NavigationContainer>
<Stack.Navigator initialRouteName={SCREENS.Loading} headerMode="none">
<Stack.Screen name={SCREENS.Loading} component={LoadingScreen} />
<Stack.Screen name={SCREENS.Landing} component={LandingScreen} />
<Stack.Screen name="AppStack" component={AppStack} />
</Stack.Navigator>
</NavigationContainer>
);
};
const App = () => {
return (
<ApolloProvider client={apolloClient}>
<AppProvider>
<AppContent />
</AppProvider>
</ApolloProvider>
);
};
I've tried sending the notification with both the data and notification fields
const message = {
topic: 'developers',
notification: {
title,
body,
},
};
const message = {
topic: 'developers',
data: {
title,
body,
},
};
The one with the notification field gets received with the app killed/in the background but getInitialNotification returns null.
The one with the data field gets received with the app killed/in the background if I use messaging().setBackgroundMessageHandler()
and notifee.onBackgroundEvent()
and I can display a local notification but it won't open the app once it's tapped.
Most likely there's just something that it's not clicking for me 😅
from react-native-notifee.
and I can display a local notification but it won't open the app once it's tapped.
By default, it doesn't as it's fully in your control. Have you read these docs?
Notifee does not provide any default interaction behaviour when a user presses a notification. The Android guidelines suggest a notification should always open the application when pressed. In React Native, we have multiple options to exactly how the application opens.
You need to specify a press action, and if that press action causes the app to open, the initial notification will be set ready to be consumed.
from react-native-notifee.
Closing this one - please let me know if you have issues after going through the above points.
from react-native-notifee.
There was a problem with intent handling and splash screens etc in the react-native-firebase repo, resolved with some specific steps in AndroidManifest to make the intent go to the right place crazycodeboy/react-native-splash-screen#289 (comment) - no idea at all if this applies here but if someone could confirm that they definitely don't have splash screens eating the launch intent, that might help.
Dosn't have react-native-splash-screen
still getInitialNotification doesn't work.
from react-native-notifee.
@rajnishcoder you quoted my question but did not answer. My question was a general question "splash screens" not just that module. Do you have any activity in AndroidManifest.xml set as LAUNCHER other than your MainActivity? That's the important part.
from react-native-notifee.
Related Issues (20)
- [iOS] remote notification: no custom data received when app is in background/terimnated HOT 3
- Cannot find getDeliveredNotifications in Notifee v1.10.0 HOT 1
- `cancelDisplayedNotifications` also cancels scheduled notifications on Android HOT 5
- Android custom sound not found with extension (`sound.mp3`) is found with no extension (`sound`) HOT 3
- [iOS] Help troubleshooting with the service extension? HOT 3
- [Android] Question: is it possible to use the system alert UI to show the notification HOT 2
- [Android] How can you set a dynamic custom sound per notification? HOT 2
- [iOS] help with remote notifications HOT 3
- [iOS] Should background events work with the Notifee Service Extension? HOT 5
- Installation alongside react-native-firebase - android_background_activity_names needed? HOT 2
- Update messages in conversation notification HOT 4
- getInitialNotification deprecated? HOT 4
- Get data payload from Android DisplayedNotification HOT 1
- Attempt to invoke virtual method 'android.content.Intent android.app.Activity.getIntent()' on a null object reference HOT 7
- Error: Notifee native module not found. HOT 11
- Website "My account" - cannot change user role HOT 6
- getDisplayedNotifications returning wrong ids HOT 6
- Tag is null HOT 2
- [iOS] Notification sound does not stop on cancelNotification()/cancelDisplayedNotification() HOT 3
- await notifee.displayNotification not firing notification on release build HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-notifee.