react-native-push-notification / ios

React Native Push Notification API for iOS.
MIT License
745 stars 285 forks source link

registration event not called #27

Open danielzzz opened 4 years ago

danielzzz commented 4 years ago

Bug

no events called (register, etc..)

Environment info

React native info output:

 nfo Fetching system and libraries information...
System:
    OS: macOS 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
    Memory: 19.34 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.10.0 - /usr/local/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.11.3 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
  IDEs:
    Xcode: 11.0/11A420a - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.0-rc.3 => 0.61.0-rc.3 
  npmGlobalPackages:
    react-native-cli: 2.0.1

Library version: 1.0.2

Steps To Reproduce

//ios push
// 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];
}
//--- end ios push
console.log('push ios');

    PushNotificationIOS.addEventListener('register', (token) => {
      console.log('ios registered');
      console.log(token);
      store.dispatch(set('PUSH_REGISTERED', {
        push: {
          token: token
        }
      }));
    })

    PushNotificationIOS.addEventListener('registrationError', (message) => {
      console.log('registererror');
      console.log(message);
    })

    PushNotificationIOS.addEventListener('notification', (message) => {
      console.log('notification ios');
      console.log(message);
      processNotification(message.Notification)

    })

    PushNotificationIOS.requestPermissions();
danielzzz commented 4 years ago

sorry, for some reason I cannot edit the issue. the first code block is from the AppDelegate.m and the second from my js code.

danielzzz commented 4 years ago

it might be some problem with the apns or my phone as afther a few hours of pulling my hair out, suddenly it just started working with the same code as in the beginning.

things to try:

malina commented 4 years ago

@danielzzz did you find a solution?

yannou788 commented 4 years ago

Try to go into capabilities to enable notifications in xcode

dommangetnicolas commented 4 years ago

it might be some problem with the apns or my phone as afther a few hours of pulling my hair out, suddenly it just started working with the same code as in the beginning.

things to try:

  • restarting the phone
  • uninstalling and reinstalling (to trigger asking for permissions)
  • reconnecting the usb cable

Restarting the phone was right ! Thanks a lot