gpt4 book ai didi

react-native - 如何更新 rnfirebase admob 以支持 iOS 14 AppTrackingTransparency

转载 作者:行者123 更新时间:2023-12-02 18:47:24 32 4
gpt4 key购买 nike

Google AdMob 已宣布 preparations for iOS 14+最近。需要 AppTrackingTransparency 权限。但是,对于通过 rnfirebase 使用 AdMob 的 react-native 开发人员没有路线图。 .我的 react-native 项目目前依赖于 react-native-firebase 版本 v6.7.1:

"dependencies": {
"@react-native-firebase/admob": "^6.7.1",
"@react-native-firebase/app": "^6.7.1",
...

我只是在我的应用中使用 InterstitialAdBannerAd:

import { InterstitialAd, TestIds, AdEventType, 
BannerAd, BannerAdSize} from '@react-native-firebase/admob';

升级我的项目以支持 iOS 14+ 的路线图应该是什么?

最佳答案

要进行此更新,应遵循多个步骤:

更新 react-native-firebase 依赖项

首先,您应该更新您的 react-native-firebase由于存在预请求“Google 移动广告 SDK 7.64.0 或更高版本”,因此您的 package.json 中的依赖项为最新版本:

"@react-native-firebase/admob": "^11.3.2",
"@react-native-firebase/app": "^11.3.2",

然后运行 ​​npm installyarn install 命令。

添加 react-native-permissions 依赖

其次,你应该添加一个react-native-permissions对您的 package.json 的依赖,以便稍后您将使用此依赖来检查和请求 AppTrackingTransparency 权限:

"react-native-permissions": "^3.0.2",

然后运行 ​​npm installyarn install 命令。

更新Info.plist

然后,您应该添加新需要的 NSUserTrackingUsageDescription key&value 和 SKAdNetworkItems 信息,这些信息在 Admob's Prepare for iOS 14+ document 上有说明。到您的 Info.plist 文件:

<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to deliver personalized ads to you.</string>
<key>SKAdNetworkItems</key>
<array>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>cstr6suwn9.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>4fzdc2evr5.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>2fnua5tdw4.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>ydx93a7ass.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>5a6flpkh64.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>p78axxw29g.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>v72qych5uu.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>c6k4g5qg8m.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>s39g8k73mm.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>3qy4746246.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>3sh42y64q3.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>f38h382jlk.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>hs6bdukanm.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>prcb7njmu6.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>wzmmz9fp6w.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>yclnxrl5pm.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>4468km3ulz.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>t38b2kh725.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>7ug5zh24hu.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>9rd848q2bz.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>n6fk4nfna4.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>kbd757ywx3.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>9t245vhmpl.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>2u9pt9hc89.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>8s468mfl3y.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>av6w8kgt66.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>klf5c3l5u5.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>ppxm28t8ap.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>424m5254lk.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>uw77j35x4d.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>e5fvkxwrpn.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>zq492l623r.skadnetwork</string>
</dict>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>3qcr597p9d.skadnetwork</string>
</dict>
</array>

更新 Podfile

然后,您应该通过添加以下行来更新您的 PodFile:

permissions_path = '../node_modules/react-native-permissions/ios'

pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency"

然后在你项目的ios目录下运行pod installpod install --repo-update命令(你可以删除此操作之前的旧 Pods 目录和 Podfile.lock 文件)。

在你的 react-native 代码中添加 AppTrackingTransparency 权限

最后,您应该在 AdMob 广告请求之前的某处添加检查和请求 APP_TRACKING_TRANSPARENCY 权限到您的 native 代码:

import {check, request, PERMISSIONS, RESULTS} from 'react-native-permissions';

//......

check(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY)
.then((result) => {
switch (result) {
case RESULTS.UNAVAILABLE:
console.log('This feature is not available (on this device / in this context)');
break;
case RESULTS.DENIED:
console.log('The permission has not been requested / is denied but requestable');
request(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY).then((reqResult) => {
switch (reqResult) {
case RESULTS.GRANTED:
console.log('The permission request is granted');
// now you can make ad requests
break;
case RESULTS.BLOCKED:
console.log('The permission request is denied and not requestable anymore');
break;
}
});
break;
case RESULTS.LIMITED:
console.log('The permission is limited: some actions are possible');
break;
case RESULTS.GRANTED:
console.log('The permission is granted');
// now you can make ad requests
break;
case RESULTS.BLOCKED:
console.log('The permission is denied and not requestable anymore');
break;
}
})
.catch((error) => {
// …
});

如果您从 checkrequest 方法调用中获得 RESULTS.GRANTED 结果,则可以发出广告请求。

最后说明:在运行之前,不要忘记在所有这些更改之后清理您的 Xcode 项目。

关于react-native - 如何更新 rnfirebase admob 以支持 iOS 14 AppTrackingTransparency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67254603/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com