AdvertisingInfo Module

The AdvertisingInfo module exposes advertising-related information about the device the app is running on.

Methods

getAdvertisingId()

  • Description: Returns the advertising identifier
  • Return Type: A promise object of the string type
  • Method Usage Example: AdvertisingInfo.getAdvertisingId()
  • Platforms Supported: Android, iOS, tvOS, Roku Cloud Solution, and UWP

Enable the Module

To use the AdvertisingInfo module for RN apps, you need to include the module in your app’s UserInit() as shown in the example below. For the youi-tv init app, for example, you can find the UserInit method in /youi/src/App.cpp.

#include <youireact/advertising/AdvertisingInfoModule.h>

bool App::UserInit()
{
    bool userInitSuccess = PlatformApp::UserInit();

    //To use the AdvertisingInfo module
    GetReactNativeViewController().AddModule<yi::react::AdvertisingInfoModule>();

    return userInitSuccess;
}

Example Usage

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';
import { AdvertisingInfo } from '@youi/react-native-youi';

export default class AdvertisingInfoExample extends Component {

  state = {
    advertisingId: null
  }

  componentDidMount() {
    AdvertisingInfo.getAdvertisingId().then(advertisingId => {
      this.setState({advertisingId});
    }).catch(error => {
      console.log(error);
    });
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.heading}>AdvertisingInfo exposes advertising related information about the device the app is running on.</Text>
        <Text style={styles.text}>Advertising Id: {this.state.advertisingId}</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    backgroundColor: '#d0d0d0'
  },
  heading: {
    fontSize: 16
  },
  text: {
    fontSize: 12
  }
});