Пуш-уведомление IOS звучит и вибрирует непрерывно (без остановки)
В моем приложении React Native, использующем FCM для push-уведомлений, я заметил, что когда push-уведомление появляется на переднем плане (iOS), оно продолжает вибрировать и звучать непрерывно и раздражающе и не остановится, пока я не отключу свои Данные.
Это не происходит, когда уведомление приходит, когда приложение работает в фоновом режиме.
Вот фрагмент кода конфигурации XCODE и конфигурации JavaScript.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
[RNFIRMessaging willPresentNotification:notification withCompletionHandler:completionHandler];
}
#if defined(__IPHONE_11_0)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
#else
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
#endif
//You can skip this method if you don't want to use local notification
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[RNFIRMessaging didReceiveLocalNotification:notification];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
[RNFIRMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
FCM.getFCMToken().then(token => {
console.log("TOKEN (getFCMToken)", token);
if(token !== '') {
this.props.onChangeToken(this.props.user.userid, token, Platform.OS);
}
});
if(Platform.OS === 'ios'){
FCM.getAPNSToken().then(token => {
console.log("APNS TOKEN (getFCMToken)", token);
});
}
FCM.getInitialNotification().then(notif => {
console.log("INITIAL NOTIFICATION", notif);
});
this.notificationListener = FCM.on(FCMEvent.Notification, notif => {
console.log("Notification", notif);
FCM.presentLocalNotification({
vibrate: 500,
title: notif.header,
body: notif.message,
big_text: notif.longmessage,
priority: "high",
sound: "bell.mp3",
large_icon: "ic_launcher", // Android only
icon: "ic_launcher",
click_action: "ACTION", // as FCM payload
// badge: 10, // as FCM payload IOS only, set 0 to clear badges
// number: 10, // Android only
///ticker: "My Notification Ticker",
// large_icon: "https://image.freepik.com/free-icon/small-boy-cartoon_318-38077.jpg",
show_in_foreground: true
});
if(notif.local_notification){
return;
}
if(notif.opened_from_tray){
return;
}
if(Platform.OS ==='ios'){
//optional
//iOS requires developers to call completionHandler to end notification process. If you do not call it your background remote notifications could be throttled, to read more about it see the above documentation link.
//This library handles it for you automatically with default behavior (for remote notification, finish with NoData; for WillPresent, finish depend on "show_in_foreground"). However if you want to return different result, follow the following code to override
//notif._notificationType is available for iOS platfrom
switch(notif._notificationType){
case NotificationType.Remote:
notif.finish(RemoteNotificationResult.NewData) //other types available: RemoteNotificationResult.NewData, RemoteNotificationResult.ResultFailed
break;
case NotificationType.NotificationResponse:
notif.finish();
break;
case NotificationType.WillPresent:
notif.finish(WillPresentNotificationResult.All) //other types available: WillPresentNotificationResult.None
break;
}
}
this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, token => {
console.log("TOKEN (refreshUnsubscribe)", token);
if(token !== '') {
this.props.onChangeToken(this.props.user.userid, token, Platform.OS);
}
});
// direct channel related methods are ios only
// directly channel is truned off in iOS by default, this method enables it
FCM.enableDirectChannel();
this.channelConnectionListener = FCM.on(FCMEvent.DirectChannelConnectionChanged, (data) => {
console.log('direct channel connected' + data);
});
setTimeout(function() {
FCM.isDirectChannelEstablished().then(d => console.log(d));
}, 1000);
})
}
}