Skip to content

Commit

Permalink
Merge pull request #100 from vikas-goyal-axway/MOD-2652
Browse files Browse the repository at this point in the history
feat(ios): support AppTrackingTransparency for iOS 14
  • Loading branch information
vijaysingh-axway authored Oct 19, 2020
2 parents 9b55061 + 0667bbd commit 89be709
Show file tree
Hide file tree
Showing 27 changed files with 458 additions and 288 deletions.
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ library 'pipeline-library'
def isMaster = env.BRANCH_NAME.equals('master')

buildModule {
sdkVersion = '9.0.0.v20200205134519' // use a master build with ARM64 support
iosLabels = 'osx && xcode-11'
sdkVersion = '9.2.1.GA' // use a master build with ARM64 support
iosLabels = 'osx && xcode-12'
npmPublish = isMaster // By default it'll do github release on master anyways too
npmPublishArgs = '--access public --dry-run'
}
98 changes: 98 additions & 0 deletions apidoc/Admob.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ description: |
* If using module 2.5.0+, add following key in tiapp.xml, inside ios plist section.
<key>GADIsAdManagerApp</key>
<true/>
* If using Xcode 12.0+, set minimum ios version 11.0+ using following key in tiapp.xml, inside ios section to run app on simulators.
If app supports iOS < 11.0, be sure to remove it while building for device or app distribution.
<min-ios-ver>11.0<</min-ios-ver>
Starting in iOS 14, IDFA will be unavailable until an app calls the App Tracking Transparency framework to present the app-tracking authorization request to the end user.
To display the App Tracking Transparency authorization request for accessing the IDFA, update your tiapp.xml to add the NSUserTrackingUsageDescription key with a custom message describing your usage.
Below is an example description text:
<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to deliver personalized ads to you.</string>
To present the authorization request, call requestTrackingAuthorization:. We recommend waiting for the completion callback prior to loading ads, so that if the user grants the App Tracking Transparency permission, the Google AdMob SDK can use the IDFA in ad requests.
For more information about the possible status values, see TRACKING_AUTHORIZATION_STATUS_*.
If an app does not present this request, the IDFA will automatically be zeroed out which may lead to a significant loss in ad revenue.
The Google AdMob SDK supports conversion tracking using Apple's SKAdNetwork, which means Google is able to attribute an app install even when IDFA is unavailable.
To enable this functionality, you will need to update the SKAdNetworkItems key with an additional dictionary in your tiapp.xml
<key>SKAdNetworkItems</key>
<array>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>cstr6suwn9.skadnetwork</string>
</dict>
</array>
platforms: [android, iphone, ipad]
properties:
Expand Down Expand Up @@ -89,6 +114,42 @@ properties:
permission: read-only
value: 3 # FIXME: 2 on iOS, 3 on Android

- name: TRACKING_AUTHORIZATION_STATUS_NOT_DETERMINED
type: Number
summary: Returned by `trackingAuthorizationStatus` Before a device receives an authorization request to approve access to app-related data that can be used for tracking the user or the device.
permission: read-only
value: 0
platforms: [iphone,ipad]
since: "2.6.0"
osver: {ios: {min: "14.0"}}

- name: TRACKING_AUTHORIZATION_STATUS_RESTRICTED
type: Number
summary: Returned by `trackingAuthorizationStatus` If authorization to use app tracking data is restricted
permission: read-only
value: 1
platforms: [iphone,ipad]
since: "2.6.0"
osver: {ios: {min: "14.0"}}

- name: TRACKING_AUTHORIZATION_STATUS_DENIED
type: Number
summary: Returned by `trackingAuthorizationStatus` if After a device receives an authorization request to approve access, user denied the request
permission: read-only
value: 2
platforms: [iphone,ipad]
since: "2.6.0"
osver: {ios: {min: "14.0"}}

- name: TRACKING_AUTHORIZATION_STATUS_AUTHORIZED
type: Number
summary: Returned by `trackingAuthorizationStatus` if After a device receives an authorization request to approve access, user accpet the request
permission: read-only
value: 3
platforms: [iphone,ipad]
since: "2.6.0"
osver: {ios: {min: "14.0"}}

- name: SIMULATOR_ID
type: String
summary: The deviceId for emulators to be used with <Modules.Admob.View.testDevices> property
Expand Down Expand Up @@ -214,6 +275,14 @@ properties:
# FIXME: debugGeography is read-only on iOS, but readwrite on Android!

# TODO: Android has property for isTaggedForUnderAgeOfConsent

- name: trackingAuthorizationStatus
type: Number
platforms: [iphone, ipad]
since: "2.6.0"
osver: {ios: {min: "14.0"}}
summary: Use to check tracking authorization status.
constants: Modules.Admob.TRACKING_AUTHORIZATION_STATUS_*

methods:
- name: initialize
Expand Down Expand Up @@ -320,6 +389,21 @@ methods:
type: ConsentFormOptions
summary: Options used to build the consent form

- name: requestTrackingAuthorization
summary: The request for user authorization to access app-related data.
description: |
One-time request to authorize or deny access to app-elated data that can be used for tracking the user or the device.
The system remembers the user's choice and doesn't prompt again unless a user uninstalls and then reinstalls the app on the device.
Note, when calling requestTrackingAuthorization(completionHandler:), the NSUserTrackingUsageDescription key must be in the tiapp.xml.
platforms: [iphone, ipad]
since: "2.6.0"
osver: {ios: {min: "14.0"}}
parameters:
- name: callback
type: Callback<TrackingAuthorizationStatusObject>
summary: Async callback function to invoke when done
optional: false

---
name: ConsentFormOptions
summary: Simple object type used in <Modules.Admob.showConsentForm>
Expand Down Expand Up @@ -442,4 +526,18 @@ properties:
summary: The error message in case of failure
optional: true
permission: read-only

---
name: TrackingAuthorizationStatusObject
summary: Simple object passed to callback passed in to the <Modules.Admob.requestTrackingAuthorization> method
platforms: [iphone,ipad]
since: "2.6.0"
osver: {ios: {min: "14.0"}}
properties:
- name: status
type: Number
summary: The status of Tracking Authorization
optional: false
permission: read-only
constants: Modules.Admob.TRACKING_AUTHORIZATION_STATUS_*

4 changes: 4 additions & 0 deletions ios/Classes/TiAdmobModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@

- (NSNumber *)isTaggedForUnderAgeOfConsent:(__unused id)unused;

- (NSNumber *)trackingAuthorizationStatus;

- (void)requestTrackingAuthorization:(id)args;

@end
39 changes: 39 additions & 0 deletions ios/Classes/TiAdmobModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#import "TiUtils.h"
#import <GoogleMobileAds/GoogleMobileAds.h>
#import <PersonalizedAdConsent/PersonalizedAdConsent.h>
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
#import <AppTrackingTransparency/ATTrackingManager.h>
#endif

@implementation TiAdmobModule

Expand Down Expand Up @@ -159,8 +162,44 @@ - (NSNumber *)isTaggedForUnderAgeOfConsent:(id)unused
return @([[PACConsentInformation sharedInstance] isTaggedForUnderAgeOfConsent]);
}

- (NSNumber *)trackingAuthorizationStatus
{
if (@available(iOS 14, *)) {
return @([ATTrackingManager trackingAuthorizationStatus]);
} else {
NSLog(@"[WARN] Ti.AdMob: The property `trackingAuthorizationStatus` should be used on ios version 14 and above only");
}
return @3;
}

- (void)requestTrackingAuthorization:(id)args
{
ENSURE_SINGLE_ARG(args, NSDictionary);

KrollCallback *callback = [args objectForKey:@"callback"];
if (@available(iOS 14, *)) {
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
NSNumber *trackingStatus = @(status);
if (callback != nil) {
[callback call:@[ @{ @"status" : trackingStatus } ] thisObject:self];
}
}];
return;
} else {
NSLog(@"[WARN] Ti.AdMob: The function `requestTrackingAuthorization` should be used on ios version 14 and above only");
}
if (callback != nil) {
[callback call:@[ @{ @"status" : @3 } ] thisObject:self];
}
}

#pragma mark Constants

MAKE_SYSTEM_PROP(TRACKING_AUTHORIZATION_STATUS_NOT_DETERMINED, 0);
MAKE_SYSTEM_PROP(TRACKING_AUTHORIZATION_STATUS_RESTRICTED, 1);
MAKE_SYSTEM_PROP(TRACKING_AUTHORIZATION_STATUS_DENIED, 2);
MAKE_SYSTEM_PROP(TRACKING_AUTHORIZATION_STATUS_AUTHORIZED, 3);

MAKE_SYSTEM_PROP(CONSENT_STATUS_UNKNOWN, PACConsentStatusUnknown);
MAKE_SYSTEM_PROP(CONSENT_STATUS_NON_PERSONALIZED, PACConsentStatusNonPersonalized);
MAKE_SYSTEM_PROP(CONSENT_STATUS_PERSONALIZED, PACConsentStatusPersonalized);
Expand Down
30 changes: 14 additions & 16 deletions ios/admob.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 52;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -16,7 +16,7 @@
3A4F268F1C68DDF7003E06CF /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A4F268E1C68DDF7003E06CF /* iAd.framework */; };
3AF5B7731C233383002E3DC7 /* TiAdmobTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AF5B7711C233383002E3DC7 /* TiAdmobTypes.h */; };
5E32C3FB20E2957400A17A2B /* FBAudienceNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E32C3F920E2957400A17A2B /* FBAudienceNetwork.framework */; };
5E32C3FC20E2957400A17A2B /* FacebookAdapter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E32C3FA20E2957400A17A2B /* FacebookAdapter.framework */; };
5E32C3FC20E2957400A17A2B /* FacebookAdapter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E32C3FA20E2957400A17A2B /* FacebookAdapter.framework */; platformFilter = ios; };
AA747D9F0F9514B9006C5449 /* TiAdmob_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = AA747D9E0F9514B9006C5449 /* TiAdmob_Prefix.pch */; };
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; };
CE6C17A01982D1170017C788 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE6C179F1982D1170017C788 /* AdSupport.framework */; };
Expand All @@ -30,14 +30,14 @@
DB07E8B81E8010000008C1E1 /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB07E8B61E8010000008C1E1 /* CoreMedia.framework */; };
DB07E8B91E8010000008C1E1 /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB07E8B71E8010000008C1E1 /* CoreMotion.framework */; };
DB07E8BB1E80100D0008C1E1 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB07E8BA1E80100D0008C1E1 /* CoreVideo.framework */; };
DB07E8BD1E80101A0008C1E1 /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB07E8BC1E80101A0008C1E1 /* GLKit.framework */; };
DB07E8BD1E80101A0008C1E1 /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB07E8BC1E80101A0008C1E1 /* GLKit.framework */; platformFilter = ios; };
DB07E8BF1E80101F0008C1E1 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB07E8BE1E80101F0008C1E1 /* JavaScriptCore.framework */; };
DB07E8C01E80103C0008C1E1 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DAD5D7D112527E1A009CF986 /* MediaPlayer.framework */; };
DB07E8C21E80104D0008C1E1 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB07E8C11E80104D0008C1E1 /* MobileCoreServices.framework */; };
DB07E8C41E8010560008C1E1 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB07E8C31E8010560008C1E1 /* OpenGLES.framework */; };
DB07E8C21E80104D0008C1E1 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB07E8C11E80104D0008C1E1 /* MobileCoreServices.framework */; platformFilter = ios; };
DB07E8C41E8010560008C1E1 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB07E8C31E8010560008C1E1 /* OpenGLES.framework */; platformFilter = ios; };
DB07E8C61E8010680008C1E1 /* SafariServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB07E8C51E8010680008C1E1 /* SafariServices.framework */; };
DB2840FB20B408760099933A /* GoogleMobileAds.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB2840FA20B408760099933A /* GoogleMobileAds.framework */; };
DB28410420B413750099933A /* PersonalizedAdConsent.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB28410320B413750099933A /* PersonalizedAdConsent.framework */; };
DB28410420B413750099933A /* PersonalizedAdConsent.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB28410320B413750099933A /* PersonalizedAdConsent.framework */; platformFilter = ios; };
F71D3A0D2534725800F2BBB6 /* GoogleMobileAds.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB2840FA20B408760099933A /* GoogleMobileAds.framework */; platformFilter = ios; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -81,7 +81,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
DB2840FB20B408760099933A /* GoogleMobileAds.framework in Frameworks */,
F71D3A0D2534725800F2BBB6 /* GoogleMobileAds.framework in Frameworks */,
DB28410420B413750099933A /* PersonalizedAdConsent.framework in Frameworks */,
3A4F268F1C68DDF7003E06CF /* iAd.framework in Frameworks */,
CE6C17A01982D1170017C788 /* AdSupport.framework in Frameworks */,
Expand Down Expand Up @@ -265,6 +265,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEPLOYMENT_POSTPROCESSING = NO;
DSTROOT = /tmp/TiAdmob.dst;
EXCLUDED_ARCHS = i386;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/GoogleMobileAdsSdkiOS",
Expand All @@ -287,11 +288,8 @@
GCC_WARN_UNUSED_VALUE = NO;
GCC_WARN_UNUSED_VARIABLE = NO;
HEADER_SEARCH_PATHS = (
"$(TITANIUM_BASE_SDK)",
"$(TITANIUM_BASE_SDK2)",
"~$(TITANIUM_BASE_SDK)",
"~$(TITANIUM_BASE_SDK2)",
"$(SRCROOT)/GoogleMobileAdsSdkiOS",
"$(HEADER_SEARCH_PATHS)",
);
INSTALL_PATH = /usr/local/lib;
LIBRARY_SEARCH_PATHS = (
Expand Down Expand Up @@ -321,6 +319,7 @@
ALWAYS_SEARCH_USER_PATHS = NO;
DEPLOYMENT_POSTPROCESSING = YES;
DSTROOT = /tmp/TiAdmob.dst;
EXCLUDED_ARCHS = i386;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/GoogleMobileAdsSdkiOS",
Expand All @@ -343,11 +342,8 @@
GCC_WARN_UNUSED_VALUE = NO;
GCC_WARN_UNUSED_VARIABLE = NO;
HEADER_SEARCH_PATHS = (
"$(TITANIUM_BASE_SDK)",
"$(TITANIUM_BASE_SDK2)",
"~$(TITANIUM_BASE_SDK)",
"~$(TITANIUM_BASE_SDK2)",
"$(SRCROOT)/GoogleMobileAdsSdkiOS",
"$(HEADER_SEARCH_PATHS)",
);
INSTALL_PATH = /usr/local/lib;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
Expand Down Expand Up @@ -377,6 +373,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DSTROOT = /tmp/TiAdmob.dst;
ENABLE_TESTABILITY = YES;
EXCLUDED_ARCHS = i386;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
Expand Down Expand Up @@ -417,6 +414,7 @@
CLANG_ENABLE_MODULES = YES;
DEPLOYMENT_POSTPROCESSING = YES;
DSTROOT = /tmp/TiAdmob.dst;
EXCLUDED_ARCHS = i386;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
Expand Down
Loading

0 comments on commit 89be709

Please sign in to comment.