[React Native] add support for reading tracking bit
This commit is contained in:
parent
24da269404
commit
582d8f062a
|
@ -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({
|
|||
<Text style={styles.title}>Advertising ID: </Text>
|
||||
{JSON.stringify(this.state.deviceID)}
|
||||
</Text>
|
||||
<Text>
|
||||
<Text style={styles.title}>Has Advertiser Tracking: </Text>
|
||||
{JSON.stringify(this.state.hasAdvertiserTracking)}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -11,4 +11,8 @@ module.exports = {
|
|||
getAdvertisingId: function(onSuccess, onFailure) {
|
||||
AdSupport.getAdvertisingId(onSuccess, onFailure);
|
||||
},
|
||||
|
||||
getAdvertisingTrackingEnabled: function(onSuccess, onFailure) {
|
||||
AdSupport.getAdvertisingTrackingEnabled(onSuccess, onFailure);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue