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

Jor*_*ris 5 javascript reactjs react-native appsflyer

我正在尝试在React本机应用程序中实现AppsFlyer,但出现此错误“无法读取未定义的属性'initSdk'”

我导入了react-native-appsflyer

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

import appsFlyer from 'react-native-appsflyer';

//...
Run Code Online (Sandbox Code Playgroud)

并尝试调用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);
           }
           )
     }
Run Code Online (Sandbox Code Playgroud)

并在我的startApp函数中启动它

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

        switch (root) {
          //...  
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有人帮我好吗?

小智 0

如果本机依赖项未正确链接,则可能会出现此错误,如果您react-native link react-native-appsflyer从项目的根目录运行(对于 Android 本机依赖项)并为 iOS 添加相关 Pod 依赖项,则应该可以解决此错误:

将 appsFlyerFramework 添加到 Podfile 并运行 pod install。例子:

pod 'react-native-appsflyer',
:path => '../node_modules/react-native-appsflyer'
Run Code Online (Sandbox Code Playgroud)

(假设你的Podfile位于iOS目录中)运行pod install

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