From 582d8f062abd78534f566be029f078a812cd9f7d Mon Sep 17 00:00:00 2001 From: Owen Coutts Date: Thu, 12 Mar 2015 15:57:48 -0700 Subject: [PATCH] [React Native] add support for reading tracking bit --- Examples/UIExplorer/AdSupportIOSExample.js | 30 +++++++++++++++++++--- Libraries/AdSupport/AdSupportIOS.js | 4 +++ Libraries/AdSupport/RCTAdSupport.m | 12 +++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Examples/UIExplorer/AdSupportIOSExample.js b/Examples/UIExplorer/AdSupportIOSExample.js index 63f3a63eb..a3d720f01 100644 --- a/Examples/UIExplorer/AdSupportIOSExample.js +++ b/Examples/UIExplorer/AdSupportIOSExample.js @@ -29,23 +29,41 @@ var AdSupportIOSExample = React.createClass({ getInitialState: function() { return { deviceID: 'No IDFA yet', + hasAdvertiserTracking: 'unset', }; }, componentDidMount: function() { AdSupportIOS.getAdvertisingId( - this._onSuccess, - this._onFailure + this._onDeviceIDSuccess, + this._onDeviceIDFailure + ); + + AdSupportIOS.getAdvertisingTrackingEnabled( + this._onHasTrackingSuccess, + this._onHasTrackingFailure ); }, - _onSuccess: function(deviceID) { + _onHasTrackingSuccess: function(hasTracking) { + this.setState({ + 'hasAdvertiserTracking': hasTracking, + }); + }, + + _onHasTrackingFailure: function(e) { + this.setState({ + 'hasAdvertiserTracking': 'Error!', + }); + }, + + _onDeviceIDSuccess: function(deviceID) { this.setState({ 'deviceID': deviceID, }); }, - _onFailure: function(e) { + _onDeviceIDFailure: function(e) { this.setState({ 'deviceID': 'Error!', }); @@ -58,6 +76,10 @@ var AdSupportIOSExample = React.createClass({ Advertising ID: {JSON.stringify(this.state.deviceID)} + + Has Advertiser Tracking: + {JSON.stringify(this.state.hasAdvertiserTracking)} + ); } diff --git a/Libraries/AdSupport/AdSupportIOS.js b/Libraries/AdSupport/AdSupportIOS.js index 598befd31..c0a081aa4 100644 --- a/Libraries/AdSupport/AdSupportIOS.js +++ b/Libraries/AdSupport/AdSupportIOS.js @@ -11,4 +11,8 @@ module.exports = { getAdvertisingId: function(onSuccess, onFailure) { AdSupport.getAdvertisingId(onSuccess, onFailure); }, + + getAdvertisingTrackingEnabled: function(onSuccess, onFailure) { + AdSupport.getAdvertisingTrackingEnabled(onSuccess, onFailure); + }, }; diff --git a/Libraries/AdSupport/RCTAdSupport.m b/Libraries/AdSupport/RCTAdSupport.m index 3712b1b9b..22ad6aacb 100644 --- a/Libraries/AdSupport/RCTAdSupport.m +++ b/Libraries/AdSupport/RCTAdSupport.m @@ -15,4 +15,16 @@ } } +- (void)getAdvertisingTrackingEnabled:(RCTResponseSenderBlock)callback withErrorCallback:(RCTResponseSenderBlock)errorCallback +{ + RCT_EXPORT(); + + if ([ASIdentifierManager class]) { + bool hasTracking = [[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]; + callback(@[@(hasTracking)]); + } else { + return errorCallback(@[@"as_identifier_unavailable"]); + } +} + @end