birgernass/react-native-ad-consent

TypeError: null is not an object

patrickjane opened this issue · 4 comments

I've followed the installation steps for iOS, and running my app on the iOS simulator, I get the following upon start:

TypeError: null is not an object (evaluating '_reactNativeAdConsent.default.requestConsenfInfoUpdate')

I have copied & pasted the example code for asking for consent into my App.js like this:

import RNAdConsent from 'react-native-ad-consent';

[...]
            const consentStatus = await RNAdConsent.requestConsentInfoUpdate({ publisherId: "myID" });

            if (consentStatus === RNAdConsent.UNKNOWN) {
               const formResponse = await RNAdConsent.showGoogleConsentForm({
                  privacyPolicyUrl: "https://your-privacy-link.com",
                  shouldOfferAdFree: false
               });

               if (formResponse === RNAdConsent.PREFERS_AD_FREE) {
                  // do stuff
               } else {
                  await RNAdConsent.setConsentStatus(formResponse)
               }
            }

I have edited AppDelegate.h/.m as advised, and also edited the Info.plist.

I also tried pod install in ios folder, althought not given by the instruction, which tells me:

skipped the react-native dependency 'react-native-ad-consent'. No podspec file was found.

In addition I have added PersonalizedAdConsent via pod but it did not help.

So in fact

import RNAdConsent from 'react-native-ad-consent';

returns null.

What do I have to do?

Which version of this library and which react-native version are you using?

react-native 0.61.5
and I've installed this module yesterday via npm install which installed v1.0.1 according to package.json.

You need version 2+ for react-native 0.60+. I'm not sure why it installed an old version for you.

The latest release was not listed on npm. I just published a new version. Thanks for letting me know!