Git Product home page Git Product logo

Comments (4)

zoontek avatar zoontek commented on May 24, 2024 1

Closed as v4.0.0 is out.

from react-native-permissions.

zoontek avatar zoontek commented on May 24, 2024

This indeed makes no sense, as denied is returned when the status is ATTrackingManagerAuthorizationStatusNotDetermined, and it should not be possible after a request.

from react-native-permissions.

jwoodmansey avatar jwoodmansey commented on May 24, 2024

My colleague has patched this, which seems to bring our analytics back in line with what we'd expect. After this patch we are now back to only getting blocked or granted returned from request, at the ratio we would expect. I'm not entirely how this fixed it, but sharing their code below...

diff --git a/node_modules/react-native-permissions/ios/AppTrackingTransparency/RNPermissionHandlerAppTrackingTransparency.m b/node_modules/react-native-permissions/ios/AppTrackingTransparency/RNPermissionHandlerAppTrackingTransparency.m
index c492b3f..46f3e8b 100644
--- a/node_modules/react-native-permissions/ios/AppTrackingTransparency/RNPermissionHandlerAppTrackingTransparency.m
+++ b/node_modules/react-native-permissions/ios/AppTrackingTransparency/RNPermissionHandlerAppTrackingTransparency.m
@@ -50,13 +50,22 @@ - (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
     }

     if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
-      [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(__unused ATTrackingManagerAuthorizationStatus status) {
-        [self checkWithResolver:resolve rejecter:reject];
+
+      [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
+          switch (status) {
+            case ATTrackingManagerAuthorizationStatusNotDetermined:
+              return resolve(RNPermissionStatusNotDetermined);
+            case ATTrackingManagerAuthorizationStatusRestricted:
+              return resolve(RNPermissionStatusRestricted);
+            case ATTrackingManagerAuthorizationStatusDenied:
+              return resolve(RNPermissionStatusDenied);
+            case ATTrackingManagerAuthorizationStatusAuthorized:
+              return resolve(RNPermissionStatusAuthorized);
+          }
       }];
     } else {
       _resolve = resolve;
       _reject = reject;
-
       [[NSNotificationCenter defaultCenter] addObserver:self
                                                selector:@selector(onApplicationDidBecomeActive:)
                                                    name:UIApplicationDidBecomeActiveNotification
@@ -71,10 +80,18 @@ - (void)onApplicationDidBecomeActive:(__unused NSNotification *)notification {
   [[NSNotificationCenter defaultCenter] removeObserver:self
                                                   name:UIApplicationDidBecomeActiveNotification
                                                 object:nil];
-
   if (@available(iOS 14.0, *)) {
-    [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(__unused ATTrackingManagerAuthorizationStatus status) {
-      [self checkWithResolver:self->_resolve rejecter:self->_reject];
+    [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
+        switch (status) {
+          case ATTrackingManagerAuthorizationStatusNotDetermined:
+            return self->_resolve(RNPermissionStatusNotDetermined);
+          case ATTrackingManagerAuthorizationStatusRestricted:
+            return self->_resolve(RNPermissionStatusRestricted);
+          case ATTrackingManagerAuthorizationStatusDenied:
+            return self->_resolve(RNPermissionStatusDenied);
+          case ATTrackingManagerAuthorizationStatusAuthorized:
+            return self->_resolve(RNPermissionStatusAuthorized);
+        }
     }];
   }
 }

from react-native-permissions.

mikehardy avatar mikehardy commented on May 24, 2024

For that patch to be effective, either the "ios14 is not available" branch is taken in checkWithResolver resulting in nothing but authorized or denied:

} else {
if ([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {
resolve(RNPermissionStatusAuthorized);
} else {
resolve(RNPermissionStatusDenied);
}

or the ios14-is-available branch is taken and the dynamic call for tracking status is somehow returning something different then the status sent in via the callback sent in with the request?

Here's the dynamic callback:

switch ([ATTrackingManager trackingAuthorizationStatus]) {

...because the result of that callback is doing the same switch you've effectively inlined in the callback definition

It would be very interesting to know which of the ios14-is-available conditional branches were used and to know if the dynamic call for status was somehow different then the status provided as a parameter to the callback.

You have a working solution which you likely don't want to mess with and possibly cause a regression, but it could be possible to maybe call check instead of request in addition to see what check says - emulating the dynamic call. Is it safe to assume ios14-is-available is returning the correct value? I think so

That all seems unexpected though, I'm pretty confused how this is happening, doesn't seem like it should unless the request status vs the dynamic check status is racy somehow in ios17 with check providing a stale value for some unknown amount of time while the callback status is fresh 🤷

from react-native-permissions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.