-
-
Notifications
You must be signed in to change notification settings - Fork 827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iOS 15 ATT permission not showing up #648
Comments
Please respect the issue template. |
@zoontek I've updated the description a little |
Are you using an iPhone? Which one? The simulator? |
@zoontek I'm checking on iPhone 8 Plus, before update to ios 15 permission was showed as expected |
@zoontek any ideas? |
Reading the Reddit thread, it seems that Apple broke the feature. The code is super basic: https://github.com/zoontek/react-native-permissions/blob/master/ios/AppTrackingTransparency/RNPermissionHandlerAppTrackingTransparency.m#L38 |
The application is active too since the app JS bundle is loaded. |
We are effected here as well, when trying to release our app 4 days ago we got hit with a rejection. Apple responded with:
Right now, we are calling The prompt appears in iOS 14, but does not occur at all in iOS 15. I've tried AppState and it does not fulfill this scenario, since it does not register on a first launch of the app. Is it possible for us to tap into |
On further studying, it would seem that Apple has made it so that iOS 15 and onwards the app must be in an That means if we're trying to fire it off on the on mount of the very first screen/component/file that gets loaded, it's going to fail. The app is not yet in an active state during the launch period despite those screens counting as being mounted. What seems to work for us right now is to just put the logic within AppState event listener, and on An example of what we're doing in the on mount event of the very root index file of our RN app. checkPermission = async () => {
const result = await check(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY);
if (result === RESULTS.DENIED) {
await request(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY);
}
};
handleAppStateChange = (nextState) => {
if (nextState === "active") {
if (Platform.OS === "ios") {
// Only once app has become active
// can we prompt app tracking permission (Apple iOS 15 requirement)
this.checkPermission();
}
}
};
componentDidMount() {
// Add a listener
AppState.addEventListener("change", this.handleAppStateChange);
}; Just to note, we're using a rather outdated version of React Native here. This project is still stuck on RN 0.61.5, hence the In RN 0.65.1 (latest at this point in time), AppState has undergone functionality removal for listeners. You may need to fiddle around with AppState differently in 0.65 onwards. The above solution seems to work in both iOS 14.5 on an iPhone 12 Pro Max, and also in iOS 15 on an iPhone 13 Pro Max. |
I just found a better way base on @sabun123 's answer. const state = useAppState();
useEffect(() => {
if (state === 'active' && Platform.OS === "ios") {
request(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY)
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
}
return () => {};
}, [state]); |
This could perhaps be added to the documentation somewhere near the ATT information? Could probably help a lot of people, it looks really clean to me |
having the same issues |
Using useEffect(() => {
const listener = AppState.addEventListener("change", (status) => {
if (Platform.OS === "ios" && status === "active") {
request(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY)
.then((result) => console.log(result))
.catch((error) => console.log(error));
}
});
return listener.remove;
}, []); |
That seems like a good enough workaround (or solution, even), but this definitely needs to go into the docs as a "Note: On iOS 15+ ..." imho. |
easily rewritten as: "That seems like a good enough workaround (or solution, even), I'll propose a PR to the docs as a "Note: On iOS 15+ ...". |
You're absolutely right. Please see #657. I sometimes forget, that "the docs" is just the README, which, in turn, is just a part of the repo like everything else! |
You can create a PR to add it. I would recommend not to specify on "iOS 15+" since there is no downside on using this method for all ATT permission requests. Just saying that in case people would add conditions to use AppState on iOS > 15 and another way on iOS =< 15. |
Fixed by #657 |
mehh still have this issue on iOS15 but it is location_permission |
This workaround does not trigger the request function when the app is first launched. It does however trigger it if you put it to background and then open the app again. But I don't understand why this would be needed if we run it from useEffect. It won't trigger even if I execute it in a useEffect later in the app. Something seems broken and I don't think this issue should be closed. |
useEffect(() => {
if (Platform.OS !== "ios") {
return; // don't create listeners on other platforms
}
const requestPermission = () => {
request(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY)
.then((result) => console.log(result))
.catch((error) => console.log(error));
};
// if the app is active when the effect is fired, request immediately
if (AppState.currentState === "active") {
return requestPermission();
}
// otherwise setup a listener…
const listener = AppState.addEventListener("change", (status) => {
if (status === "active") {
// …which will perform the request once the app is active
requestPermission();
}
});
return listener.remove;
}, []);
So no, this issue can stay closed 😄 |
Bug summary
ATT permission prompt not showing on iOS 15
Before it was working fine for iOS 14.5 and I didn't change anything.
Library version
3.0.3
Environment info
The text was updated successfully, but these errors were encountered: