简体   繁体   中英

How to add the default sound to my push notification in AppDelegate

I want to add the default sound to my push notification, so far I don't have a sound when I get notification (remote). this my code in AppDelegate in Objective-c:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
    NSURL *jsCodeLocation;
   jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
   [FIRApp configure];
   RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                  moduleName:@"X"
                                           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;

   }


 // Required to register for notifications
 - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
 {


    [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings];

 }
 // Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
   [RCTPushNotificationManager 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

{
   [RCTPushNotificationManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
     //NSLog(@"push-notification received: %@", notification)   
}
  // Required for the registrationError event.
    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
   {
     [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
}
    // Required for the localNotification event.
 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
 {
   [RCTPushNotificationManager didReceiveLocalNotification:notification];
  }

what am I missing? how to set the sound on? I have been working on that many hours and no solution so far...

thank you for the help

Solution: the problem wasn't in the AppDelegate file like I thought. the file is actually fine. the problem was in the code of the server.. this is why working code:

   Message message = Message.builder()
            .setNotification(new com.google.firebase.messaging.Notification( null,"hihihi"))
                            .setToken(registrationToken).setApnsConfig(ApnsConfig.builder().setAps(Aps.builder().setSound("default").build()).build())
            .build();

    String response = FirebaseMessaging.getInstance().send(message);

hope it will help to someone

据我所知,您的推送通知正文中必须具有声音参数。

推送通知在收到时会播放默认声音。但是,如果要更改声音,则应在有效负载和声音文件中将声音名称添加到项目中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM