Skip to content

Commit b25af2c

Browse files
authored
Merge pull request #501 from sohail-dragon/feature/att-ios14
Support ATT framework for iOS 14
2 parents b330564 + fd4d16a commit b25af2c

File tree

9 files changed

+106
-1
lines changed

9 files changed

+106
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ target 'YourAwesomeProject' do
3434

3535
permissions_path = '../node_modules/react-native-permissions/ios'
3636

37+
pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency.podspec"
3738
pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral.podspec"
3839
pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars.podspec"
3940
pod 'Permission-Camera', :path => "#{permissions_path}/Camera.podspec"
@@ -98,6 +99,8 @@ Then update your `Info.plist` with wanted permissions usage descriptions:
9899
<string>YOUR TEXT</string>
99100
<key>NSSiriUsageDescription</key>
100101
<string>YOUR TEXT</string>
102+
<key>NSUserTrackingUsageDescription</key>
103+
<string>YOUR TEXT</string>
101104

102105
<!---->
103106

example/ios/Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ target 'RNPermissionsExample' do
9494

9595
permissions_path = '../node_modules/react-native-permissions/ios'
9696

97+
pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency.podspec"
9798
pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral.podspec"
9899
pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars.podspec"
99100
pod 'Permission-Camera', :path => "#{permissions_path}/Camera.podspec"

example/ios/Podfile.lock

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ PODS:
7070
- OpenSSL-Universal (1.0.2.19):
7171
- OpenSSL-Universal/Static (= 1.0.2.19)
7272
- OpenSSL-Universal/Static (1.0.2.19)
73+
- Permission-AppTrackingTransparency (2.1.5):
74+
- RNPermissions
7375
- Permission-BluetoothPeripheral (2.1.5):
7476
- RNPermissions
7577
- Permission-Calendars (2.1.5):
@@ -355,6 +357,7 @@ DEPENDENCIES:
355357
- FlipperKit/SKIOSNetworkPlugin (~> 0.33.1)
356358
- Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`)
357359
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
360+
- Permission-AppTrackingTransparency (from `../node_modules/react-native-permissions/ios/AppTrackingTransparency.podspec`)
358361
- Permission-BluetoothPeripheral (from `../node_modules/react-native-permissions/ios/BluetoothPeripheral.podspec`)
359362
- Permission-Calendars (from `../node_modules/react-native-permissions/ios/Calendars.podspec`)
360363
- Permission-Camera (from `../node_modules/react-native-permissions/ios/Camera.podspec`)
@@ -422,6 +425,8 @@ EXTERNAL SOURCES:
422425
:podspec: "../node_modules/react-native/third-party-podspecs/Folly.podspec"
423426
glog:
424427
:podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec"
428+
Permission-AppTrackingTransparency:
429+
:path: "../node_modules/react-native-permissions/ios/AppTrackingTransparency.podspec"
425430
Permission-BluetoothPeripheral:
426431
:path: "../node_modules/react-native-permissions/ios/BluetoothPeripheral.podspec"
427432
Permission-Calendars:
@@ -514,6 +519,7 @@ SPEC CHECKSUMS:
514519
Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51
515520
glog: 1f3da668190260b06b429bb211bfbee5cd790c28
516521
OpenSSL-Universal: 8b48cc0d10c1b2923617dfe5c178aa9ed2689355
522+
Permission-AppTrackingTransparency: e9c0edf423abffca2fddee9cd8ed55e9cc7133df
517523
Permission-BluetoothPeripheral: 4663a8373072abfe3099c44cb06bf10b0c16c110
518524
Permission-Calendars: dc345e3388149514603309c621151ff3cfd5816a
519525
Permission-Camera: afad27bf90337684d4a86f3825112d648c8c4d3b
@@ -553,6 +559,6 @@ SPEC CHECKSUMS:
553559
Yoga: 3ebccbdd559724312790e7742142d062476b698e
554560
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
555561

556-
PODFILE CHECKSUM: 48265109032bce1863187d238dd58c9e3563d7e5
562+
PODFILE CHECKSUM: 33d4013cd5154539040dffe614d959a536bc61f4
557563

558564
COCOAPODS: 1.9.1
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'json'
2+
package = JSON.parse(File.read('../package.json'))
3+
4+
Pod::Spec.new do |s|
5+
s.name = "Permission-AppTrackingTransparency"
6+
s.dependency "RNPermissions"
7+
8+
s.version = package["version"]
9+
s.license = package["license"]
10+
s.summary = package["description"]
11+
s.authors = package["author"]
12+
s.homepage = package["homepage"]
13+
14+
s.platform = :ios, "9.0"
15+
s.ios.deployment_target = "9.0"
16+
s.tvos.deployment_target = "11.0"
17+
s.requires_arc = true
18+
19+
s.source = { :git => package["repository"]["url"], :tag => s.version }
20+
s.source_files = "AppTrackingTransparency/*.{h,m}"
21+
s.frameworks = "AppTrackingTransparency"
22+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import "RNPermissions.h"
2+
3+
@interface RNPermissionHandlerAppTrackingTransparency : NSObject<RNPermissionHandler>
4+
5+
@end
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#import "RNPermissionHandlerAppTrackingTransparency.h"
2+
3+
@import AppTrackingTransparency;
4+
@import AdSupport;
5+
6+
@implementation RNPermissionHandlerAppTrackingTransparency
7+
8+
+ (NSArray<NSString *> * _Nonnull)usageDescriptionKeys {
9+
return @[@"NSUserTrackingUsageDescription"];
10+
}
11+
12+
+ (NSString * _Nonnull)handlerUniqueId {
13+
return @"ios.permission.APP_TRACKING_TRANSPARENCY";
14+
}
15+
16+
- (void)checkWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
17+
rejecter:(void (__unused ^ _Nonnull)(NSError * _Nonnull))reject {
18+
if (@available(iOS 14.0, *)) {
19+
switch ([ATTrackingManager trackingAuthorizationStatus]) {
20+
case ATTrackingManagerAuthorizationStatusNotDetermined:
21+
return resolve(RNPermissionStatusNotDetermined);
22+
case ATTrackingManagerAuthorizationStatusRestricted:
23+
return resolve(RNPermissionStatusRestricted);
24+
case ATTrackingManagerAuthorizationStatusDenied:
25+
return resolve(RNPermissionStatusDenied);
26+
case ATTrackingManagerAuthorizationStatusAuthorized:
27+
return resolve(RNPermissionStatusAuthorized);
28+
}
29+
} else {
30+
NSString *idfaString = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
31+
if ([idfaString isEqualToString:@"00000000-0000-0000-0000-000000000000"]) {
32+
return resolve(RNPermissionStatusDenied);
33+
}
34+
35+
resolve(RNPermissionStatusAuthorized);
36+
}
37+
}
38+
39+
- (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
40+
rejecter:(void (^ _Nonnull)(NSError * _Nonnull))reject {
41+
if (@available(iOS 14.0, *)) {
42+
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(__unused ATTrackingManagerAuthorizationStatus status) {
43+
[self checkWithResolver:resolve rejecter:reject];
44+
}];
45+
} else {
46+
[self checkWithResolver:resolve rejecter:reject];
47+
}
48+
}
49+
50+
@end

ios/RNPermissions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ typedef NS_ENUM(NSInteger, RNPermission) {
4848
#if __has_include("RNPermissionHandlerStoreKit.h")
4949
RNPermissionStoreKit = 15,
5050
#endif
51+
#if __has_include("RNPermissionHandlerAppTrackingTransparency.h")
52+
RNPermissionAppTrackingTransparency = 16,
53+
#endif
5154
};
5255

5356
@interface RCTConvert (RNPermission)

ios/RNPermissions.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
#if __has_include("RNPermissionHandlerStoreKit.h")
5050
#import "RNPermissionHandlerStoreKit.h"
5151
#endif
52+
#if __has_include("RNPermissionHandlerAppTrackingTransparency.h")
53+
#import "RNPermissionHandlerAppTrackingTransparency.h"
54+
#endif
5255

5356
static NSString* SETTING_KEY = @"@RNPermissions:Requested";
5457

@@ -100,6 +103,9 @@ @implementation RCTConvert(RNPermission)
100103
#if __has_include("RNPermissionHandlerStoreKit.h")
101104
[RNPermissionHandlerStoreKit handlerUniqueId]: @(RNPermissionStoreKit),
102105
#endif
106+
#if __has_include("RNPermissionHandlerAppTrackingTransparency.h")
107+
[RNPermissionHandlerAppTrackingTransparency handlerUniqueId]: @(RNPermissionAppTrackingTransparency),
108+
#endif
103109
}), RNPermissionUnknown, integerValue);
104110

105111
@end
@@ -173,6 +179,9 @@ - (NSDictionary *)constantsToExport {
173179
#if __has_include("RNPermissionHandlerStoreKit.h")
174180
[available addObject:[RNPermissionHandlerStoreKit handlerUniqueId]];
175181
#endif
182+
#if __has_include("RNPermissionHandlerAppTrackingTransparency.h")
183+
[available addObject:[RNPermissionHandlerAppTrackingTransparency handlerUniqueId]];
184+
#endif
176185

177186
#if RCT_DEV
178187
if ([available count] == 0) {
@@ -268,6 +277,11 @@ - (NSDictionary *)constantsToExport {
268277
case RNPermissionStoreKit:
269278
handler = [RNPermissionHandlerStoreKit new];
270279
break;
280+
#endif
281+
#if __has_include("RNPermissionHandlerAppTrackingTransparency.h")
282+
case RNPermissionAppTrackingTransparency:
283+
handler = [RNPermissionHandlerAppTrackingTransparency new];
284+
break;
271285
#endif
272286
case RNPermissionUnknown:
273287
break; // RCTConvert prevents this case

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const ANDROID = Object.freeze({
3131
});
3232

3333
export const IOS = Object.freeze({
34+
APP_TRACKING_TRANSPARENCY: 'ios.permission.APP_TRACKING_TRANSPARENCY' as const,
3435
BLUETOOTH_PERIPHERAL: 'ios.permission.BLUETOOTH_PERIPHERAL' as const,
3536
CALENDARS: 'ios.permission.CALENDARS' as const,
3637
CAMERA: 'ios.permission.CAMERA' as const,

0 commit comments

Comments
 (0)