Open arnoldas500 opened 4 years ago
Hi,
I think this issue is not only related to register
.
Same issue seems to occur on notification
event and is not triggered.
Experiencing the same issue. Using react-native-push-notification which in turn uses this package. Any updates?
Edit: So the callback is only not triggered, when building the app in debug mode. Release build works.
Same issue +1
I managed to make it work by requesting the permission first, then calling the listener in the callback of checkPermission()
Example:
PushNotificationIOS.requestPermissions();
PushNotificationIOS.checkPermissions(function () {
PushNotificationIOS.addEventListener('register', (token) => {
console.log("MyAPNSTOKEN", token)
})
});
I always get the apnsToken now, hope it can help
Rebooting my device helped. Following this note: https://github.com/react-native-community/push-notification-ios/pull/97/files
Same thing. Old project (worked fine few months ago) without any commits not working anymore — no errors, no token. Reboot not helped, trying another device — not working. I try to create new empty projects (0.62.0 and 0.62.2) only with this package — same result. My current project (0.62.2) working fine yesterday morning stoped working at evening )) How I can find APN log? Console, Flipper, Analytics Ddta show nothing.
Putting listeners in checkPermissions not helped too.
certificates are up-to-date?
Sure.
Capabilities enabled:
I can upload empty example app on github.
https://github.com/bragovo/push-example - this is example app. Alert in simulator and nothing on any real devices (7, XS, SE).
I'm using react@16.8.6 and react-native@0.60.6. And the following codes are working for me.
// e.g. 1
PushNotificationIOS.requestPermissions();
PushNotificationIOS.addEventListener('register', (token) => {
console.log("MyAPNSTOKEN", token);
});
// e.g. 2
PushNotificationIOS.requestPermissions().then(() => {
PushNotificationIOS.addEventListener('register', (token) => {
console.log("MyAPNSTOKEN", token);
});
});
Thanks for @hpiso's comment.
Any news on this issue? Facing the same problem.
EDIT: Ok after many investigations, I concluded it's a phone/apple cache problem. I had to uninstall the app, uninstall test flight, stop wifi & reboot the phone 2 times. (messing between testflight version & dev version probably didn't help).
And tada! It magically worked again! So as said @lumberman, rebooting phone/uninstalling app and trying to clean the phone should help. Hope it'll help, good luck!
I was able to get the token by making changes to my AppDelegate.mm file. Removed all notification related code recommended by README install section and replaced with: //top of file:
//bottom of file before @end
// Required to register for notifications
Hope this helps others who are having the same issue of not producing an APNS token.
I was able to get the token by making changes to my AppDelegate.mm file. Removed all notification related code recommended by README install section and replaced with: //top of file:
import
import <UserNotifications/UserNotifications.h>
//bottom of file before @EnD
pragma mark - Notifications
// Required to register for notifications
- (void)application:(UIApplication )application didRegisterUserNotificationSettings:(UIUserNotificationSettings )notificationSettings { [RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings]; } // Required for the register event.
- (void)application:(UIApplication )application didRegisterForRemoteNotificationsWithDeviceToken:(NSData )deviceToken { [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication )application didReceiveRemoteNotification:(NSDictionary )userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } // Required for the registrationError event.
- (void)application:(UIApplication )application didFailToRegisterForRemoteNotificationsWithError:(NSError )error { [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error]; } // Required for the localNotification event.
- (void)application:(UIApplication )application didReceiveLocalNotification:(UILocalNotification )notification { [RNCPushNotificationIOS didReceiveLocalNotification:notification]; }
Hope this helps others who are having the same issue of not producing an APNS token.
this is EXACTLY the same code as the documentation
I had the same problem, I checked AppDelegate and checked a few "fixes" and I found a solution. I'm firstly set up a listener and after that, I requestPerrmissions (previously I've used listeners when an alert from requestPermissions was true). I found this idea here. So currently (pseudocode):
const registerPushNotifications = async () => {
PushNotificationIOS.addEventListener('register', deviceToken => {
I'm saving Token from here
})
PushNotificationIOS.addEventListener('notification', showNotification)
}
const unregisterPushNotifications = () => {
PushNotificationIOS.removeEventListener('notification', showNotification)
PushNotificationIOS.removeEventListener('register', registerTokenCallback)
}
const someFunction = async () => {
await registerPushNotifications();
PushNotificationIOS.requestPermissions().then(def => {
if (!def.alert) {
unregisterPushNotifications()
}
})
}
Bug
Environment info
react-native info
output:info React Native Environment Info: System: OS: macOS 10.15.2 CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz Memory: 749.49 MB / 32.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node npm: 6.9.0 - ~/.nvm/versions/node/v10.16.0/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1 Android SDK: API Levels: 21, 22, 23, 25, 26, 27, 28 Build Tools: 22.0.1, 25.0.0, 26.0.1, 26.0.2, 28.0.3, 29.0.0 System Images: android-21 | Google APIs Intel x86 Atom, android-25 | Google Play Intel x86 Atom, android-26 | Google APIs Intel x86 Atom IDEs: Android Studio: 3.5 AI-191.8026.42.35.5791312 Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild npmPackages: react: 16.8.3 => 16.8.3 react-native: https://github.com/expo/react-native/archive/sdk-34.0.1.tar.gz => 0.59.8 npmGlobalPackages: react-native-cli: 2.0.1 react-native-git-upgrade: 0.2.7 react-native-log-ios: 1.0.1 react-native-vector-icons: 6.6.0
Library version: 1.1.1
Steps To Reproduce
Describe what you expected to happen:
1.App loads and ask for push notification permissions (this works) 2.Console logs the device token (does not work and no token is printed)
Reproducible sample code
async componentDidMount() { console.log('component did mount PushNotificationHandler') PushNotificationIOS.addEventListener('register', token => { console.log("* PushNotificationHandler CALLLEDDD ***** ", token) Alert.alert(token) })
}