Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-native-idfa

ptomasroos9.9kMIT4.1.0

Android and iOS module for react-native to read IDFA (advertising identifier)

react-native-idfa, react-component, react-components, react, native, idfa, advertisingIdentifier, react-native, component, ios, android

readme

react-native-idfa

Retrieve the advertising identifier across ios and android on react-native with this small library. Support RN > 0.56 with or without and cocoapods

Build Status npm version npm downloads

How to install

npm install react-native-idfa
react-native link

Since this library is using the advertising identifier, you must remember to add AdSupport in your IOS project.

If you're using Cocoapods, there is no need to this as when you're adding react-native-idfa to your Podfile it will get added by default

Podfile

  pod 'react-native-idfa',  path: '../node_modules/react-native-idfa'

Add AdSupport.framework under "Link Binary With Libraries".

How to use!

import { IDFA } from 'react-native-idfa';

class Basic extends Component {
  state = {
     IDFA: '',
  };

  componentDidMount() {
    IDFA.getIDFA().then((idfa) => {
      this.setState({ IDFA: idfa, });
    })
    .catch((e) => {
      console.error(e);
    });
  }

  render() {
    return (
      <View style={{ flex: 1 }}>
        <Text>Your IDFA is : {this.state.IDFA}</Text>
      </View>
    );
  }
}

Changing react-native-idfa's com.google.android.gms:play-services-ads version

In your build.gradle make sure to force the version to whatever version makes sense through our your dependencies

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.getRequested().getGroup() == 'com.google.android.gms') {
            // If different projects require different versions of
            // Google Play Services it causes a crash on run.
            // Fix by overriding version for all projects.
            details.useVersion('17.0.0')
        }
    }
}

Known flaws

Since this is a react-native repository we will ship the code untranspiled and with flow types along it.

Using gms 17.0.0

Google has introduced some breaking changes on 17.0.0. The SDK will throw an error if your manifest.xml is not configured properly

    ******************************************************************************
    * The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
    * should follow the instructions here: https://goo.gl/fQ2neu to add a valid  *
    * App ID inside the AndroidManifest. Google Ad Manager publishers should     *
    * follow instructions here: https://goo.gl/h17b6x.                           *
    ******************************************************************************

changelog

4.1.0

Since jcenter wiped old build tools on their side we're forced to upgrade this

Upgraded Android buildToolsVersion to 28.0.3 and compileSdkVersion to 28

4.0.3

Added running e2e tests Various clean ups Added flowtype definitions

4.0.2

Some small refactorings and added example/Basic into main repo Added explicit LICENSE file

4.0.1

Just updated README to reflect the new naming

4.0.0

Renamed project to allow usage from gradle 5.0

3.0.0

Ignore garbage from being published to npm Allow the project to respect the root project's compileSdkVersion, buildToolsVersion, minSdkVersion, targetSdkVersion

2.1.0

  • minSdkVersion is now 16 instead of 21

2.0.0

  • Removed dead code from examples/Basic
  • Updated Podspec to contain correct repo
  • Fixed import statement in README
  • Enable BITCODE in ios
  • Supporting < 10 since of the change below
  • Making sure to check wether we can return and invoke the advertising id in both platforms or not
  • Updated google play services to use latest version always in gradle config, if you want another version see resolver solution: https://github.com/ptomasroos/react-native-idfa/issues/10#issuecomment-357412582 -