【问题标题】:Why facebook app links are not working in react native为什么 facebook 应用程序链接在本机反应中不起作用
【发布时间】:2022-01-08 20:19:48
【问题描述】:

我正在尝试为我的 react-native 应用程序集成 facebook 应用程序链接,不幸的是它似乎没有按预期工作。首先,我按照文档中提到的说明进行操作。所以我使用了 react-native-facebook-app-link 并尝试使用 ads helper 进行验证,但我无法获取 url。

这是我添加的代码,

<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:windowSoftInputMode="adjustPan"
        android:exported="true">

          <intent-filter>
              <data android:scheme="sample" android:host="open"/>
              <action android:name="android.intent.action.VIEW"/>
              <category android:name="android.intent.category.DEFAULT"/>
              <category android:name="android.intent.category.BROWSABLE"/>
          </intent-filter>

      </activity>

我已经在清单文件中添加了密钥,

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>

<meta-data android:name="com.facebook.sdk.AdvertiserIDCollectionEnabled"
        android:value="true"/>

我也实现了这个方法,

@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
      AppLinkData.fetchDeferredAppLinkData(this,
          new AppLinkData.CompletionHandler() {
              @Override
              public void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
                    Log.d("urls", String.valueOf(appLinkData));
              }
          }
      );
  }

由于我正在使用 react native 构建应用程序,因此我在 app.js 中添加了以下代码,

async componentDidMount () {
        FacebookAppLink.initializeSDK();
        const url = await FacebookAppLink.fetchUrl();
        if(url){
           console.log("FACEBOOOK URL: ", url)
        }
}

最后,我尝试使用广告助手, enter image description here

但是我没有收到 URL。它被重定向到应用程序,但 url 没有打印在控制台中。请注意我遵循的步骤是,

  1. 已卸载应用
  2. 生成了链接,我在 facebook 中收到了通知
  3. 使用 android studio 重建和安装应用
  4. 然后点击那个链接

我不确定我做错了什么。一些帮助将不胜感激。提前致谢。

【问题讨论】:

  • 你能添加一个repro GitHub示例吗?
  • @SHA,请提供 GitHub 存储库链接。

标签: android react-native facebook deep-linking applinks


【解决方案1】:

我认为你不需要在你的项目中再次实现以下原生方法

@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
      AppLinkData.fetchDeferredAppLinkData(this,
          new AppLinkData.CompletionHandler() {
              @Override
              public void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
                    Log.d("urls", String.valueOf(appLinkData));
              }
          }
      );
  }

它已经在该库中实现,并从那里解析/拒绝承诺。

你只需要写你在componentDidMount写的东西,它应该可以工作。

【讨论】:

    猜你喜欢
    • 2020-11-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    相关资源
    最近更新 更多