iOS 14.5 反应本机应用程序中 firebase 日志的应用程序跟踪透明度

iOS 14.5 App Tracking Transparency for firebase logs in react-native app

Firebase 日志在我正在使用的 react-native 应用程序更新到 iOS 14.5 后立即停止工作。

我们需要做哪些必要的更改才能使其再次运行?

你需要先申请Tracking权限(我用的是react-native-permissions):

import { request, RESULTS, PERMISSIONS } from 'react-native-permissions'
import { Settings } from 'react-native-fbsdk-next'

export const requestPermissionTransparency = async () => {
  return await request(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY)
}

useEffect(() => {
    ;(async () => {
      const result = await requestPermissionTransparency()
      if (result === RESULTS.GRANTED) {
        await firebase.analytics().setAnalyticsCollectionEnabled(true)
        await Settings.setAdvertiserTrackingEnabled(true)
      } else {
        await firebase.analytics().setAnalyticsCollectionEnabled(false)
        await Settings.setAdvertiserTrackingEnabled(false)
      }
    })()
  }, [])

记得在根项目中添加这个文件:

// <project-root>/firebase.json
{
  "react-native": {
    "analytics_auto_collection_enabled": false
  }
}

参考文献:https://rnfirebase.io/analytics/usage