简体   繁体   English

如何使用React Native为IOS正确安装Facebook Ads

[英]How to properly install Facebook Ads for IOS using React Native

I'm getting a warning in React Native when trying to launch my app via IOS: 尝试通过IOS启动我的应用程序时,我在React Native中收到警告:

"Module AdChoiceManager requires main queue setup since it overrides 'init' but doesn't implement 'requiresMainQueueSetup'. In a future release React Native will default to initializing all native modules on a background thread unless explicitly opted-out of." “模块AdChoiceManager需要设置主队列,因为它会覆盖'init'但不会实现'requiresMainQueueSetup'。在未来的版本中,除非明确选择退出,否则React Native将默认在后台线程上初始化所有本机模块。”

In my podfile, I have these 在我的Podfile中,我有这些

pod 'react-native-fbsdk', :path => '../node_modules/react-native-fbsdk'
pod 'FBAudienceNetwork', '~> 5.1.0'

I get the error: 我得到错误:

[!] /bin/bash -c 
set -e
npm install --production

/bin/bash: line 2: npm: command not found

So I tried this: 所以我尝试了这个:

  pod 'FBAudienceNetwork', '~> 5.1.0' 
  pod 'FacebookSDK'
  pod 'FBSDKShareKit'
  pod 'FBSDKLoginKit'

Everything installs but I still get the warning. 一切都安装了,但我仍然收到警告。 It works fine on Android, I'm just not sure how to get Facebook Ads working properly, without warning on IOS. 它可以在Android上正常运行,但我不确定如何在不警告IOS的情况下使Facebook Ads正常运行。

My question is, how do I resolve this issue/warning? 我的问题是,如何解决此问题/警告? I've been trying for days to get this off the screen to no avail. 我已经尝试了好几天才能将其从屏幕上删除,但无济于事。

This is a problem with the dependency. 这是依赖的问题。 It is not a major issue but it will require fixing by the dependency maintainer in the future. 这不是主要问题,但是将来需要依赖维护者进行修复。

It is to do with the queue/thread the dependency is running on. 它与运行依赖项的队列/线程有关。 It only affects iOS. 它仅影响iOS。

There is nothing you can do at the moment to remove the warning. 您目前无法删除警告。

You could just hide the yellow warning box but it will still log the warning in your console. 您可以隐藏黄色警告框,但仍将警告记录在控制台中。

import { YellowBox } from 'react-native';

YellowBox.ignoreWarnings(['Module AdChoiceManager requires main queue setup since']); 

https://facebook.github.io/react-native/docs/debugging#in-app-errors-and-warnings https://facebook.github.io/react-native/docs/debugging#in-app-errors-and-warnings

I'm not 100% sure that is the correct text to use for blocking it, but it will be something similar to that. 我不是100%确信这是用于阻止它的正确文本,但是会与此类似。 Usually I just the text from the start of the warning 通常我只是警告开头的文字

To fix the issue 解决问题

The only way to solve the issue is to fix it in the dependency its self. 解决此问题的唯一方法是将其修复为自身依赖项。 You will have to fork the repo that is causing the issue, make the change, create a pull request and wait for Facebook to merge your change. 您将必须派生导致问题的存储库,进行更改,创建拉取请求,然后等待Facebook合并您的更改。 While you're waiting you can use your own fork. 等待期间,您可以使用自己的叉子。

Inside the correct file, it will end in ... Manager.m You just have to add the line 在正确的文件内,它将以... Manager.m结尾... Manager.m您只需添加行

+ (BOOL) requiresMainQueueSetup { return YES; }

There maybe more than one place this has to be done dependening in how they have set it up the dependency. 取决于他们如何设置依赖关系,可能有多个地方需要这样做。 This will stop the warning as you will told the dependency which queue it requires. 当您告诉依赖项需要哪个队列时,这将停止警告。

Warning, you will now have to maintain your own version of the dependency until such times that Facebook implement your pull request. 警告,您现在必须维护自己的依赖版本,直到Facebook实现您的拉取请求为止。

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

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