我想在推送通知中添加默认声音,到目前为止,当我收到通知(远程)时我没有声音。这是我在Objective-c的AppDelegate
中的代码:
- (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];
}
我想念什么?如何设置声音?到目前为止,我已经工作了许多小时,却没有解决方案...
感谢您的帮助
解决方案: 问题不是我想的那样在AppDelegate文件中。该文件实际上很好。问题出在服务器代码中。 这就是为什么工作代码:
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);
希望它将对某人有所帮助
答案 0 :(得分:0)
据我所知,您的推送通知正文中必须有一个声音参数。
答案 1 :(得分:0)
推送通知在收到时播放默认声音。 但是,如果要更改声音,则应在有效负载和声音文件中将声音名称添加到项目中。