leegeunhyeok / react-native-zendesk-messaging

🗣️ Zendesk messaging SDK for React Native
https://www.npmjs.com/package/react-native-zendesk-messaging
MIT License
40 stars 12 forks source link

[iOS] Push Notification not showing in background/quit state #44

Closed fmedinaUtoppia closed 7 months ago

fmedinaUtoppia commented 8 months ago

Describe the bug I think i configured well the sdk. I turned the entitlements to production, I set the .p12 in the zendesk admin center platform. What I am doing wrong? I am testing it in the production environment of the app. Thanks for your help.

Expected behavior Showing push notifications in background/quit states when I receive a message from the chat In App.

AppDelegate.h

#import <RCTAppDelegate.h>
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : RCTAppDelegate <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>
@end

AppDeletage.m

#import <Firebase.h>

#import <React/RCTBundleURLProvider.h>
#import "RNSplashScreen.h" 
#import <CodePush/CodePush.h>
#import <UserNotifications/UserNotifications.h>
#import <ZendeskNativeModule.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIRApp configure];

  bool didFinish=[super application:application didFinishLaunchingWithOptions:launchOptions];

  [RNSplashScreen show];

  [self registerForPushNotifications];

  return didFinish;

}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  [ZendeskNativeModule updatePushNotificationToken:deviceToken];
}

// (1. Show push notifications)
// ZendeskNativeModule.showNotification
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
        willPresentNotification:(UNNotification *)notification
        withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {

  id userInfo = notification.request.content.userInfo;
  BOOL isHandled = [ZendeskNativeModule showNotification:userInfo completionHandler:completionHandler];

  if (isHandled) return;

  // other handing code here

  // If not handled, you should call the `completionHandler` before end of `userNotificationCenter` method
  completionHandler(UNNotificationPresentationOptionNone);
}

// (2. Handle tap notifications)
// ZendeskNativeModule.handleNotification
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
        didReceiveNotificationResponse:(UNNotificationResponse *)response
        withCompletionHandler:(void (^)(void))completionHandler {

  id userInfo = response.notification.request.content.userInfo;

  BOOL isHandled = [ZendeskNativeModule handleNotification:userInfo completionHandler:completionHandler];

  if (isHandled) return;

  // other handing code here

  // If not handled, you should call the `completionHandler` before end of `userNotificationCenter` method
  completionHandler();
}

- (void)registerForPushNotifications {
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
      center.delegate = self;
      [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge)
         completionHandler:^(BOOL allowed, NSError * _Nullable error) {
        if (allowed) {
          dispatch_async(dispatch_get_main_queue(), ^{
              [[UIApplication sharedApplication] registerForRemoteNotifications];
          });
        }
    }];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
  #if DEBUG
    return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
  #else
    return [CodePush bundleURL];

  #endif
}

@end

Environment (please complete the following information):

RP-alissonpaschoal commented 8 months ago

I have the same problem. It works on Android, but on iOS I do not receive any push notification from Zendesk

fmedinaUtoppia commented 8 months ago

I have the same problem. It works on Android, but on iOS I do not receive any push notification from Zendesk

Can I ask you if you have tested in testflight?

Edit:

Tested in testflight works as spected.