Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PushNotification iOS notification sound send error #974

Closed
Draccan opened this issue Apr 12, 2018 · 3 comments
Closed

PushNotification iOS notification sound send error #974

Draccan opened this issue Apr 12, 2018 · 3 comments
Assignees
Labels

Comments

@Draccan
Copy link

Draccan commented Apr 12, 2018

iOS 11 Simulator
React Native version: 0.52.2
RNFirebase Version: 4.0.1

Hi guys I have a problem setting the sound in the iOSNotification (local!). I have use the default Android sound in emulator and real Android device using Notification.setSound("default") and it works well.
On iOS simulator (I don't have real device) I receive an error if I set the Notification sound.

When the push notification arrives I execute this code with the purpose to display the notification (app is foreground):

`

        const FCN = firebase.notifications();
        var n = new firebase.notifications.Notification();

	n.setBody("Hi, my name is Paul");
	n.setData({isLocal:true});
	n.setTitle("Dear Jack")
	n.setSound("default"); // <-- NOT WORKING WITH THIS LINE

	FCN.displayNotification(n).then((result) => {
		LOG.debug("PushNotificationsHelper :: notification displayed");
	}, (error) => {
		LOG.error("PushNotificationsHelper :: error showing notification")
	});`

The error is a bit strange and it's shown when FCN.displayNotification fails:
schermata 2018-04-12 alle 17 01 53

  • Is the notification shown if you remove setSound? Yes
  • Does setSound works with Android? Yes
  • Have you tried on a real device? No, I don't have one
  • Should work even on simulator? I think that simulator has no problems with sounds

Podfile:

`

  platform :ios, '9.0'

  target 'asilo' do

  pod 'RSKImageCropper'
  pod 'QBImagePickerController'
  pod 'Firebase/Core'
  pod 'Firebase/Auth'
  pod 'Firebase/Database'
  pod 'Firebase/Storage'
  pod 'Firebase/Messaging'

  end`

AppDelegate.m:

`

  #import "AppDelegate.h"

  #import <Firebase.h>
  #import "RNFirebaseMessaging.h"
  #import "RNFirebaseNotifications.h"
  #import <React/RCTBundleURLProvider.h>
  #import <React/RCTRootView.h>

  @implementation AppDelegate

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
    NSURL *jsCodeLocation;

   jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

    [FIRApp configure];
    [RNFirebaseNotifications configure];
    [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];

    [FIRDatabase database].persistenceEnabled = NO;
    RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                  moduleName:@"asilo"
                                           initialProperties:nil
                                               launchOptions:launchOptions];
    rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    UIViewController *rootViewController = [UIViewController new];
    rootViewController.view = rootView;
    self.window.rootViewController = rootViewController;
    [self.window makeKeyAndVisible];
    return YES;
  }

  - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    [[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
  }

  - (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
                                                   fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
    [[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
  }

  - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
   [[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings];
  }

  @end

`

AppDelegate.h:
`

  #import <UIKit/UIKit.h>
  @import UserNotifications;

  @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>

  @property (nonatomic, strong) UIWindow *window;

  @end`

If you need something else let me know..!

Thank you for helping us :)

@chrisbianca
Copy link
Contributor

Thanks for flagging, I've just pushed up a fix that will be part of v4.0.3

@shapovalstas
Copy link

@chrisbianca this is great news!

@pkhien95
Copy link

@chrisbianca I'm using v4.2.0 and still cannot set sound for ios notification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants