Closed gerardus1995 closed 2 years ago
Did you follow the steps in the https://facebook.github.io/react-native/docs/pushnotificationios.html
Yes! I did everything.
I'm getting the notifications to pop up, and the onnotification method is working.
So can this be closed? Given that the onNotification method is working?
Well the bug here is that onregister is not getting called so i can't get the token.
@gerardus1995 if your running on the simulator, the onRegister method won't get called. You need to run on an actual device. I had the same issue the first time.
I can't seem to get the onRegister
handler to fire either. I'm running on a device and requestPermissions
is set to true
@nicotroia I had the same issue when I was first setting it up. I took the following steps to make sure everything was ok:
1) Make sure you have generated a certificate for Push-Notifications for your apple developer app id.
2) Make sure the updated provisioning file is attached to your iOs project.
3) Make sure the capabilities for your iOs X-Code project is set to On/Enabled for Push Notifications
4) Make sure your create a NotificationController component that get's called at the root level of your app.
Hopefully that helps you :).
None of this works for me for trying to just get my APNS token on iOS
I installed and linked everything along with deleting and reinstalling the app, but onRegister is never being called on my device even though I get the notifications permission request. I accept them and then onRegister is not called.
This is really disappointing as all I want is the device token and I can't get it.
I was trying to use react-native-fcm, but they don't allow you to grab APNS token. Is it possible there's some kid of conflict?
In my case, it was in fact react-native-fcm AppDelegate methods that were conflicting with PushNotificationIOS AppDelegate methods. Removing the react-native-fcm methods fixed my issue.
I have same issue but in android not in IOS. onRegister method is not called in android.
Same problem in android, Any update?
Same problem on Android, it works for iOS but not being called in Android at all.
Any update?
@roysG I just managed to make it work. Here is how: Go to https://console.firebase.google.com and create a project, then find your Sender ID following this guide https://dev.tapjoy.com/faq/how-to-find-sender-id-and-api-key-for-gcm/ then copy paste your Sender ID inside the PushNotification.configure method like so:
PushNotification.configure({
senderID: '***************',
...
})
Make sure the above code is inside the componentDidMount function of your app.js file or however you called your main file.
Checking..
i did it, no errors, but also the device is not asking for me to allow the permissions for the notifications.(android galaxy s5)
can you check with console.log("TOKEN", token) to see if you get it? I'm on Moto 4 and it's not asking for permission on Android apparently but still works
i put some akert in the current event (onRegister) also on event onError, none of them cb fired
This is drive me crazy, i will try now also in other device.
Make sure you're not inserting senderID inside the onRegister function, it has to be outside, like so:
PushNotification.configure({
senderID: '***********',
onNotification: function(notification) {
....
},
onRegister: function(token) {
console.log("TOKEN", token)
....
}
})
Mazal Tov :))) I did not wrote the name of the componentDidMount As needed
it worked for me in both emulator and the devices when I did the manual install in android, especially the permissions in AndroidManifest.xml
receiving notifications also worked in an android emulator (make sure you're using an google api system and you're logged in with your account)
I had the same problem (onRegister not called) on Android emulator and devices and it was fixed adding this line on AndroidManifest.xml:
<application ....>
.........
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
.........
</application>
onRegister takes almost 1 minute to be fired on iOS.
I was messing a lot with configuration and when I added line that was in @giankotarola comment it generated a token successfully! On Android. đŸ™‚
react-native 0.55.2 react-native-push-notification 3.1.1
++ I have same issue, I have tried everything which is written here and no reaction..
@giankotarola that solved it for me ! thanks
@giankotarola thanks buddy, your solution worked for me....was facing a similar problem
https://github.com/leemlwando/reactNative-redux-boilerplate.git
@leemlwando or @1nfinity-5starZ, would you mind posting what your PushNotification.onRegister
call looks like?
I can't get it to trigger for the life of me. Tried everything in this thread and others.
@leemlwando or @1nfinity-5starZ, would you mind posting what your
PushNotification.onRegister
call looks like?I can't get it to trigger for the life of me. Tried everything in this thread and others.
check AndroidManifest.xml of https://github.com/leemlwando/reactNative-redux-boilerplate.git. i was working on that project
I have a file called NotifService.js `import PushNotification from 'react-native-push-notification';
export default class NotifService {
constructor(onRegister, onNotif) { this.configure(onRegister, onNotif);
this.lastId = 0;
}
configure(onRegister, onNotif) { PushNotification.configure({ // (optional) Called when Token is generated (iOS and Android) onRegister: onRegister,
// (required) Called when a remote or local notification is opened or received
onNotification: onNotif,
// ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
senderID: "SENDERID",
// IOS ONLY (optional): default: all - Permissions to register.
permissions: {
alert: true,
badge: true,
sound: true
},
// Should the initial notification be popped automatically
// default: true
popInitialNotification: true,
/**
* (optional) default: true
* - Specified if permissions (ios) and token (android and ios) will requested or not,
* - if not, you must call PushNotificationsHandler.requestPermissions() later
*/
requestPermissions: true,
});
} }`
and then on App.native.js:
`import React, { Component } from 'react'; import { Provider } from 'react-redux'; import { PushNotificationIOS, Platform } from 'react-native'; import { PersistGate } from 'redux-persist/lib/integration/react';
import Template from './src/Template'; import FullScreenLoading from './src/components/common/FullScreenLoading'; import { persistor, store } from './src/states';
import NotifService from './NotifService';
export default class App extends Component{ constructor(props){ super(props);
this.notif = new NotifService(this.onRegister, this.onNotif);
this.state = {
deviceToken: null,
}
}
onNotif = (notif) => { console.log(notif); if(notif.userInteraction || notif.foreground && Platform.OS == 'ios') { this.setState({ additionalData: { navigateTo: notif.navigateTo || (notif.data || {}).navigateTo } }) } notif.finish(PushNotificationIOS.FetchResult.NoData); }
onRegister = (token) => { console.log({token}) this.setState({ deviceToken: token }); }
render() { return(
);
} }`
I had the same problem (onRegister not called) on Android emulator and devices and it was fixed adding this line on AndroidManifest.xml:
<application ....> ......... <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/> ......... </application>
Thanks a lot! This should be in the documentation
I followed instructions of @arthedza but onRegister() was not called on my Android device.
Hi, I am not using Firebase but I want to use PushNotification.configure method so as to detect when user press button in the notification. But if i use PushNotification.configure I am getting "Default FirebaseApp is not initialized in this process. Make sure to call FirebaseApp.initiazwApp(Context) first" error.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.
In android everything is working fine, but in ios i don't get the token (onregister not called), eventought i get localnotifications and the onnotification method is called. I have xcode capabilities enabled and everything setup correctly i think. Here is my configure code:
registerPushNotification(){ PushNotification.configure({
}