[React Native] add support for reading tracking bit

This commit is contained in:
Owen Coutts 2015-03-12 15:57:48 -07:00
parent 24da269404
commit 582d8f062a
3 changed files with 42 additions and 4 deletions

View File

@ -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>
);
}

View File

@ -11,4 +11,8 @@ module.exports = {
getAdvertisingId: function(onSuccess, onFailure) {
AdSupport.getAdvertisingId(onSuccess, onFailure);
},
getAdvertisingTrackingEnabled: function(onSuccess, onFailure) {
AdSupport.getAdvertisingTrackingEnabled(onSuccess, onFailure);
},
};

View File

@ -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