IOS foreground push notification not showing
RN : 0.70 clevertap-react-native: 0.9.0 Platform : OS
Whats done :
useEffect(() => {
CleverTap.registerForPush()
requestUserPermission() // registering listner
notificationListener() // registering listner
CleverTap.recordEvent('some_event_to_recod')
CleverTap.createNotificationChannel(
'my_channel',
'Clever Tap React Native Testing',
'CT React Native Testing',
5,
true,
)
}, [])
My Util file
import { Alert } from 'react-native'
import { getItem, setItem } from 'Utils/utils'
export async function requestUserPermission() {
const authStatus = await messaging().requestPermission()
const enabled = authStatus === messaging.AuthorizationStatus.AUTHORIZED
|| authStatus === messaging.AuthorizationStatus.PROVISIONAL
if (enabled) {
console.log('Authorization status:', authStatus)
getFcmToken()
}
}
export const getFcmToken = async () => {
const checkToken = await getItem('fcmToken')
console.log('the old token', checkToken)
if (!checkToken) {
try {
const fcmToken = await messaging().getToken()
if (fcmToken) {
console.log('fcm token generated', fcmToken)
await setItem('fcmToken', fcmToken)
}
} catch (error) {
console.log('error in fcmToken', error)
Alert.alert(error?.message)
}
}
}
export const notificationListener = async () => {
messaging().onNotificationOpenedApp((remoteMessage) => {
console.log(
'Notification caused app to open from background state:',
remoteMessage.notification,
)
console.log('background state ', remoteMessage.notification)
})
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
console.log('Message handled in the background!', remoteMessage)
})
// Check whether an initial notification is available
messaging()
.getInitialNotification()
.then((remoteMessage) => {
if (remoteMessage) {
console.log(
'Notification caused app to open from quit state:',
remoteMessage.notification,
)
console.log('remoteMessage', remoteMessage.notification)
}
})
messaging().onMessage(async (remoteMessage) => {
console.log('received in foreground ', remoteMessage)
})
}
whats happening :
getting the push notification in the background
whats not working :
i am not getting push notification in the foreground, not even my listener is being called for foreground
Alright @eramudeep, please allow us some time to reproduce and debug this.
Hi @piyush-kukadiya able to find any workaround ?
I am facing the same issue for IOS, not able to receive the push notification from cleverTap when app is in foreground state.
@Shridhar-CN we are actively debugging this on our end. We will update you on this as soon as possible 👍
@Shridhar-CN we are actively debugging this on our end. We will update you on this as soon as possible 👍
@akashvercetti any update on the issue?
We have checked the behaviour in our sample app where foreground push notifications are getting invoked with react-native version 0.64 and CleverTap version 0.9.4 Refer: https://github.com/CleverTap/clevertap-react-native/blob/master/Example/ios/Example/AppDelegate.m
Make sure to add UNUserNotificationCenter delegate to self before sending notification as added in sample AppDelegate file, and implement the willPresent delegate methods:
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
Thank you.