javascript - 无法读取未定义的属性“initSdk”-Appsflyer 集成 React Native
问题描述
我正在尝试在反应本机应用程序中实现 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';
//...
并尝试调用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);
}
)
}
并在我的 startApp 函数中启动它
startApp(root) {
this.initSdk();
console.log('app store update --> root', root);
switch (root) {
//...
}
}
}
有人帮我吗?
解决方案
react-native link react-native-appsflyer
如果未正确链接本机依赖项,则可能会出现此错误,如果您从项目的根目录运行(对于 Android 本机依赖项)并为 iOS 添加相关的 Pod 依赖项,则应解决此错误:
将 appsFlyerFramework 添加到 Podfile 并运行 pod install。例子:
pod 'react-native-appsflyer',
:path => '../node_modules/react-native-appsflyer'
(假设您的 Podfile 位于 iOS 目录中)运行pod install
如果您不使用 cocoapods,您可以按照手动集成说明进行操作:https ://github.com/AppsFlyerSDK/react-native-appsflyer#manual-integration-integrating-without-cocoapods
推荐阅读
- azure-devops - 尝试使用 Azure DevOps 进行 SqlAzureDacpacDeployment 时,找不到使用搜索模式部署的文件
- pytorch - 如何将 Numba 用于 Pytorch 张量?
- sql - 表上的大规模更新。错误“消息 512 - 子查询返回超过 1 个值。...'
- powershell - 从 Inno Setup 执行的 PowerShell 脚本失败,并显示“检索具有 CLSID {XXXX} 的组件的 COM 类工厂失败 - 错误 80040154”
- apache-zookeeper - Apache Zookeeper:无法访问数据目录
- asp.net - Angular9 多个复选框删除
- rsync - 我们可以使用增量校验和计算复制文件吗?
- javascript - Select2 下拉菜单 - 滚动条不可用
- reactjs - 如何在反应中一次将样式应用于多个类?
- angular - Nativescript / Angular中的导航-共享模块中的Backfunction?