2015-03-11 02:11:28 +00:00
|
|
|
/**
|
2016-07-12 12:51:57 +00:00
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2015-03-26 18:24:15 +00:00
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
2015-03-23 22:07:33 +00:00
|
|
|
*
|
2015-03-26 18:24:15 +00:00
|
|
|
* Facebook reserves all rights not expressly granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2015-03-23 22:07:33 +00:00
|
|
|
*
|
2015-03-23 17:06:16 +00:00
|
|
|
* @flow
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule AdSupportIOSExample
|
2015-03-11 02:11:28 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2015-03-11 02:11:28 +00:00
|
|
|
var {
|
2015-07-01 01:44:02 +00:00
|
|
|
AdSupportIOS,
|
2015-03-11 02:11:28 +00:00
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
View,
|
2016-04-09 03:36:40 +00:00
|
|
|
} = ReactNative;
|
2015-03-11 02:11:28 +00:00
|
|
|
|
|
|
|
exports.framework = 'React';
|
|
|
|
exports.title = 'Advertising ID';
|
|
|
|
exports.description = 'Example of using the ad support API.';
|
|
|
|
|
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Ad Support IOS',
|
2016-10-16 11:11:59 +00:00
|
|
|
render: function(): React.Element<any> {
|
2015-03-11 02:11:28 +00:00
|
|
|
return <AdSupportIOSExample />;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class AdSupportIOSExample extends React.Component {
|
|
|
|
state = {
|
|
|
|
deviceID: 'No IDFA yet',
|
|
|
|
hasAdvertiserTracking: 'unset',
|
|
|
|
};
|
2015-03-11 02:11:28 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
componentDidMount() {
|
2015-03-11 02:11:28 +00:00
|
|
|
AdSupportIOS.getAdvertisingId(
|
2015-03-13 22:30:31 +00:00
|
|
|
this._onDeviceIDSuccess,
|
|
|
|
this._onDeviceIDFailure
|
2015-03-11 02:11:28 +00:00
|
|
|
);
|
2015-03-13 22:30:31 +00:00
|
|
|
|
|
|
|
AdSupportIOS.getAdvertisingTrackingEnabled(
|
|
|
|
this._onHasTrackingSuccess,
|
|
|
|
this._onHasTrackingFailure
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-03-13 22:30:31 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_onHasTrackingSuccess = (hasTracking) => {
|
2015-03-13 22:30:31 +00:00
|
|
|
this.setState({
|
|
|
|
'hasAdvertiserTracking': hasTracking,
|
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-11 02:11:28 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_onHasTrackingFailure = (e) => {
|
2015-03-13 22:30:31 +00:00
|
|
|
this.setState({
|
|
|
|
'hasAdvertiserTracking': 'Error!',
|
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-13 22:30:31 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_onDeviceIDSuccess = (deviceID) => {
|
2015-03-11 02:11:28 +00:00
|
|
|
this.setState({
|
|
|
|
'deviceID': deviceID,
|
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-11 02:11:28 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_onDeviceIDFailure = (e) => {
|
2015-03-11 02:11:28 +00:00
|
|
|
this.setState({
|
|
|
|
'deviceID': 'Error!',
|
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-11 02:11:28 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-03-11 02:11:28 +00:00
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Text>
|
|
|
|
<Text style={styles.title}>Advertising ID: </Text>
|
|
|
|
{JSON.stringify(this.state.deviceID)}
|
|
|
|
</Text>
|
2015-03-13 22:30:31 +00:00
|
|
|
<Text>
|
|
|
|
<Text style={styles.title}>Has Advertiser Tracking: </Text>
|
|
|
|
{JSON.stringify(this.state.hasAdvertiserTracking)}
|
|
|
|
</Text>
|
2015-03-11 02:11:28 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-03-11 02:11:28 +00:00
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
title: {
|
2015-03-26 01:19:28 +00:00
|
|
|
fontWeight: '500',
|
2015-03-11 02:11:28 +00:00
|
|
|
},
|
|
|
|
});
|