Expo addNotificationResponseReceivedListener doesn't work - react-native

this is my code:
React.useEffect(() => {
const subscription = Notifications.addNotificationResponseReceivedListener(response => {
console.log(response)
});
return () => subscription.remove();
}, [navigation]);
What I expect to happen is that when the user clicks on the notification, the console.log is triggered, but nothing happens
I don't know if this is an issue with expo SDK 38

I had the same issue. I was on SDK 39.
Problem was resolved once I upgraded to SDK 40.
Link to github issue: https://github.com/expo/expo/issues/9866

I could solve the problem:
I was using this listener in development mode in a Samsung Galaxy s7 Edge and didn't work. But when I published the APP in the play store this listener was working fine!

Related

OneSignal notification does not appear on iOS, but it does on Android (In App message works perfectly on both)

So I added onesignal-expo-plugin and react-native-onesignal to my project, I made everything what was wrote on the website
After this i made a developmen-simulator build for my app
I tested the app on IOS and on Android too, on android i get the notification instantly but on IOS i'm not.
So i checked the notification report on OneSignal dashboard and the ios fall into failed. I checked everything, I added everything what i had to, the p12 file is correct, I did everything multiple times before i write here,
I haven't ejected my ios app because I want to keep expo managing my ios/android application well.
What should I try to fix this issue?
Android works correctly but ios don't and I really need your help!
The in-app message works correctly just the push notification don't
Versions:
"react-native-onesignal": "^4.5.0",
"onesignal-expo-plugin": "^1.3.0",
I don't want to eject my ios code and I saw too many articles and videos how others use it and works. Please help me whats wrong.
My code example what I tried just now:
const initialOnesignal = async () => {
OneSignal.setAppId('HIDEN FOR STACKOVERFLOW');
OneSignal.promptForPushNotificationsWithUserResponse();
OneSignal.setNotificationWillShowInForegroundHandler(
notificationReceivedEvent => {
console.log(
'OneSignal: notification will show in foreground:',
notificationReceivedEvent,
);
let notification = notificationReceivedEvent.getNotification();
console.log('notification: ', notification);
const data = notification.additionalData;
console.log('additionalData: ', data);
notificationReceivedEvent.complete(notification);
},
);
OneSignal.setNotificationOpenedHandler(notification => {
console.log('OneSignal: notification opened:', notification);
});
};
And I also tried this way:
useEffect(() => {
OneSignal.setAppId('HIDEN FOR STACKOVERFLOW');
OneSignal.promptForPushNotificationsWithUserResponse(response => {
console.log('Prompt response:', response);
});
OneSignal.setNotificationWillShowInForegroundHandler(
notificationReceivedEvent => {
console.log(
'OneSignal: notification will show in foreground:',
notificationReceivedEvent,
);
let notification = notificationReceivedEvent.getNotification();
console.log('notification: ', notification);
const data = notification.additionalData;
console.log('additionalData: ', data);
// Complete with null means don't show a notification.
notificationReceivedEvent.complete(notification);
},
);
OneSignal.setNotificationOpenedHandler(notification => {
console.log('OneSignal: notification opened:', notification);
});
}, []);
Tried to only add my AppId as well. I guess i tried everyting.
I have tried to regenerate p12 file, try multiple code examples, run on simultaor and on device too.
Tried to use useEffect and simple function as well.

React-Native Expo Managed App: How do I enable sharing?

I'm using Expo SDK v. 45, iPhone 13 Pro (iOS v. 15.5), expo-sharing v. 10.1.1.
I'm currently using expo start --dev-client to test my app on my iPhone. I need to be able to share a file, created inside the app, with the outside world. I found expo-sharing to achieve this. Unfortunately, when I run
install * as Sharing from 'expo-sharing';
...
useEffect( async () => {
const canShare = await Sharing.isAvailableAsync();
if (canShare) {
console.log("available");
} else {
console.log("Not available");
}
}, []);
I get 'Not available'.
What must I do to get my app to allow sharing? I can't find anything in the Expo documentation.
Thank you.
In case anybody else has a similar issue: all I had to do was rebuild the app and reinstall it on my phone. Now it works.

[expo-ads-admob][IOS [Android works]] - Rewarded add closes immediately

So I have ejected my Expo app a while ago and now would like to use the expo-ads-admob package for the Admob integration. I followed the installation instructions and I can successfully show Banners ads in the Android and IOS app. The Android app also worked without a problem using the Reward app. However the IOS app closes the Rewarded app immediately.
The idea is that users view a Rewarded Ad and afterwards a upload with selected information starts.
The problem is that on IOS the ad is loaded, viewable for a second and I can hear the audio start, however it instantly closes and the app continues uploading. The Android app waits until users close the app and after closing starts the submitHandler.
Is anyone familiar with this problem and knows a fix? Below is some code and explanation to hopefully understand it better;
Users click on a upload button and get the choice to pay or do it for free. After selecting free the addUsingAdHandler is started. SetisAddMode closes the modal, after that I get the console log the ad is started and the video is shown.
const addUsingAdHandler = async () => {
setIsAddMode(false)
console.log('Rewared video is shown')
await AdMobRewarded.showAdAsync();
}
On opening the page I add the eventListeners as instructed. The rewardedVideoDidClose listener is used to eventually start the upload.
useEffect(() => {
AdMobRewarded.setTestDeviceID("EMULATOR");
AdMobRewarded.setAdUnitID('ca-app-pub-3940256099942544/5224354917');
AdMobRewarded.addEventListener("rewardedVideoDidRewardUser", () =>
console.log("Reward is binnen gekomen. ")
);
AdMobRewarded.requestAdAsync();
AdMobRewarded.addEventListener("rewardedVideoDidLoad", () =>
console.log("Video did load")
);
AdMobRewarded.addEventListener("rewardedVideoDidFailToLoad", () =>
console.log("Failed to load")
);
AdMobRewarded.addEventListener("rewardedVideoDidOpen", () =>
console.log("Video did open")
);
AdMobRewarded.addEventListener("rewardedVideoDidClose", () => {
console.log("video did close")
submitHandler()
}
);
AdMobRewarded.addEventListener("rewardedVideoWillLeaveApplication", () =>
console.log("Video did leave application")
);
AdMobRewarded.addEventListener("rewardedVideoDidStart", () =>
console.log("Video did start")
);
}, [])
So When pushing the upload for free button the ad is shown for a second however it inmediatly is closed (logs show this using the event listeners) and the upload starts as expected. On my Android emulator the ad is shown until I press the close button as I would expect to have also on my IOS emulator.
Has anyone come across this as well before and/or could guide me in the right direction in fixen this?
React-Native version; 0.59.10
Expo Version; 35.0.0
Expo-ads-admob version: 8.0.0

How to detect screenshots with React Native (both Android and iOS)

I am trying to detect if a user takes a screenshot while using a smartphone app that I have built. I am building my project with React Native.
I have been told that I can possibly prevent screenshots for Android but not for iOS. but can I still detect whether a user attempts to take a screenshot so that I can at least send a warning via Alert?
Thanks in advance
I tried react-native-screenshot-detector but it did not work
you can use this package it supports android&ios screenshot detecting react-native-detector
import {
addScreenshotListener,
removeScreenshotListener,
} from 'react-native-detector';
// ...
React.useEffect(() => {
const userDidScreenshot = () => {
console.log('User took screenshot');
};
const listener = addScreenshotListener(userDidScreenshot);
return () => {
removeScreenshotListener(listener);
};
}, []);
There is no package for it currently.

How to register a headset button event in react native?

I'm using the latest version of React Native. I'm trying to console log something whenever the headset button is clicked on Android. So far, I've been unsuccessful.
I tried the react-native-music-control. In the docs it says that
MusicControl.on('togglePlayPause', ()=>{console.log('clicked')})
should work. But I'm not sure if its only for ios or android too.
This is my componentDidMount (the render returns a 'hello' text).
componentDidMount() {
MusicControl.enableControl('play', true);
MusicControl.enableControl('pause', true);
MusicControl.enableControl('stop', true);
MusicControl.enableControl('togglePlayPause', true);
MusicControl.on('play', () => { console.log('----'); });
MusicControl.on('pause', () => { console.log('----'); });
MusicControl.on('togglePlayPause', () => { console.log('----'); });
}
'----' is logged only when I disconnect the headset and not any other time.
The official doc on github says:
MusicControl.on('togglePlayPause', ()=> {}); // iOS only
The iOS only comment states pretty clearly that this event is only available on iOS and would not trigger on Android
So, the package react-native-keyevent works really well with android. After linking the package, I had to configure it in the MainActivity.java (which I was skipping by mistake).
After I did that, it worked properly in Android.