简体   繁体   English

无法读取未定义的属性'initSdk' - Appsflyer集成React Native

[英]Cannot read property 'initSdk' of undefined - Appsflyer integration React Native

I'm trying to implement AppsFlyer in a react native app but I have this error "Cannot read property 'initSdk' of undefined" 我正在尝试在本机应用程序中实现AppsFlyer,但我有这个错误“无法读取未定义的属性'initSdk'”

I imported react-native-appsflyer 我导入了react-native-appsflyer

import React, { Component } from 'react';
import {
 Alert,
 Platform,
 AppRegistry,
 NetInfo,
 Text,
} from 'react-native';
//...

import appsFlyer from 'react-native-appsflyer';

//...

And tried to call the initSdk method 并试图调用initSdk方法

export default class  App extends Component {

    initSdk(){
        console.log('allo appsflyer');

        let options = {
          devKey:  'AF_DEV_KEY',
          appId: "IOS_APP_ID",
          isDebug: true
        };

       appsFlyer.initSdk(options,
           (result) => {
             this.setState( { ...this.state, initSdkResponse: result });
             console.log(initSdkResponse);
           },
           (error) => {
             console.error(error);
           }
           )
     }

And launched it in my startApp function 并在我的startApp函数中启动它

    startApp(root) {
        this.initSdk();
        console.log('app store update --> root', root);

        switch (root) {
          //...  
        }
    }
}

Someone to help me please ? 有人帮我吗?

This error might occur if the native dependencies were not properly linked, this should be resolved if you run react-native link react-native-appsflyer from the project's root (for Android native dependencies) and add relevant Pod dependencies for iOS: 如果未正确链接本机依赖项,​​则可能会发生此错误,如果您从项目的根目录(针对Android本机依赖项)运行react-native link react-native-appsflyer并为iOS添加相关的Pod依赖项,则应解决此问题:

Add the appsFlyerFramework to Podfile and run pod install. 将appsFlyerFramework添加到Podfile并运行pod install。 Example: 例:

pod 'react-native-appsflyer',
:path => '../node_modules/react-native-appsflyer'

(assuming your Podfile is located in iOS directory) Run pod install (假设您的Podfile位于iOS目录中)运行pod install

If you are not using cocoapods you can follow the manual integration instructions: https://github.com/AppsFlyerSDK/react-native-appsflyer#manual-integration-integrating-without-cocoapods 如果您不使用cocoapods,您可以按照手动集成说明进行操作: https//github.com/AppsFlyerSDK/react-native-appsflyer#manual-integration-integrating-without-cocoapods

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM