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:
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 :)
Thanks for flagging, I've just pushed up a fix that will be part of v4.0.3
@chrisbianca this is great news!
@chrisbianca I'm using v4.2.0 and still cannot set sound for ios notification.
Most helpful comment
@chrisbianca I'm using v4.2.0 and still cannot set sound for ios notification.