React-native-onesignal: didReceiveRemoteNotification no funciona en AppDelegate.m

Creado en 30 oct. 2018  ·  4Comentarios  ·  Fuente: OneSignal/react-native-onesignal

Descripción:

Estoy tratando de usar Freschat SDK para manejar sus notificaciones push dentro de AppDelegate.m pero parece que no funciona con la extensión de servicio oneignal.

Medio ambiente

  1. ¿Qué versión de OneSignal React-Native SDK está utilizando? 3.2.7
  2. ¿Cómo agregaste el SDK a tu proyecto (por ejemplo, npm) npm

Pasos para reproducir el problema:

  • Instale el SDK de OneSignal usando npm en su proyecto

  • Inicializar el SDK en el AppDelegate de iOS
  • Intenta recibir una notificación push
  • Algo más:

    (trazas de pila de fallos, así como cualquier otra información aquí)

    Comentario más útil

    Perdón por la respuesta (muy) retrasada aquí, pero hay algunas cosas.

    En primer lugar, application:didReceiveRemoteNotification: está en desuso. En su lugar, querrá usar application:didReceiveRemoteNotification:fetchCompletionHandler: . Pero recomendaría no usar esto también, definitivamente debería usar los métodos UNUserNotificationCenterDelegate si desea ejecutar código nativo cuando se recibe una notificación.

    La extensión del servicio de notificación no anula este método.

    Para usar UNUserNotificationCenterDelegate , edite AppDelegate.h y agregue:

    #import <UserNotifications/UserNotifications.h>
    

    Luego cambie la interfaz AppDelegate para implementar el protocolo UNUserNotificationCenterDelegate :

    <strong i="18">@interface</strong> AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
    

    En AppDelegate.m dentro del método didFinishLaunchingWithOptions: , debe agregar la siguiente línea:

    UNUserNotificationCenter.currentNotificationCenter.delegate = self;
    

    Finalmente, puede agregar el siguiente método que ahora se llamará cada vez que se reciba una notificación:

    -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
      //do stuff
    }
    

    Cerrando porque esto no es un problema con nuestro SDK

    Todos 4 comentarios

    @ nitish1099 ¿Qué quiere decir cuando dice "no parece funcionar con la extensión de servicio OneSignal" ...?

    Además, el SDK de Freschat es de código cerrado, por lo que, desafortunadamente, no podemos hacer mucho en términos de depurar la incompatibilidad. Cuando eliminas su SDK de tu proyecto, ¿se llama al método AppDelegate?

    Es posible que deba utilizar los métodos UNUserNotificationCenterDelegate lugar para recibir llamadas al método de evento de notificación

    @ Nightsd01 No siendo un desarrollador nativo, ¿puede decirme si la extensión del servicio de notificación anula la notificación didReceiveRemoteNotification? También podría decirme cómo usar UNUserNotificationCenterDelegate o si puede compartir una guía a la que pueda referirme.

    @ Nightsd01 ¿ Alguna actualización?

    Perdón por la respuesta (muy) retrasada aquí, pero hay algunas cosas.

    En primer lugar, application:didReceiveRemoteNotification: está en desuso. En su lugar, querrá usar application:didReceiveRemoteNotification:fetchCompletionHandler: . Pero recomendaría no usar esto también, definitivamente debería usar los métodos UNUserNotificationCenterDelegate si desea ejecutar código nativo cuando se recibe una notificación.

    La extensión del servicio de notificación no anula este método.

    Para usar UNUserNotificationCenterDelegate , edite AppDelegate.h y agregue:

    #import <UserNotifications/UserNotifications.h>
    

    Luego cambie la interfaz AppDelegate para implementar el protocolo UNUserNotificationCenterDelegate :

    <strong i="18">@interface</strong> AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
    

    En AppDelegate.m dentro del método didFinishLaunchingWithOptions: , debe agregar la siguiente línea:

    UNUserNotificationCenter.currentNotificationCenter.delegate = self;
    

    Finalmente, puede agregar el siguiente método que ahora se llamará cada vez que se reciba una notificación:

    -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
      //do stuff
    }
    

    Cerrando porque esto no es un problema con nuestro SDK

    ¿Fue útil esta página
    0 / 5 - 0 calificaciones