- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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",
...
我只是在我的应用中使用 InterstitialAd
和 BannerAd
:
import { InterstitialAd, TestIds, AdEventType,
BannerAd, BannerAdSize} from '@react-native-firebase/admob';
升级我的项目以支持 iOS 14+ 的路线图应该是什么?
最佳答案
要进行此更新,应遵循多个步骤:
首先,您应该更新您的 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 install
或 yarn install
命令。
其次,你应该添加一个react-native-permissions对您的 package.json
的依赖,以便稍后您将使用此依赖来检查和请求 AppTrackingTransparency
权限:
"react-native-permissions": "^3.0.2",
然后运行 npm install
或 yarn install
命令。
然后,您应该添加新需要的 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
:
permissions_path = '../node_modules/react-native-permissions/ios'
pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency"
然后在你项目的ios
目录下运行pod install
或pod install --repo-update
命令(你可以删除此操作之前的旧 Pods
目录和 Podfile.lock
文件)。
最后,您应该在 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) => {
// …
});
如果您从 check
或 request
方法调用中获得 RESULTS.GRANTED
结果,则可以发出广告请求。
最后说明:在运行之前,不要忘记在所有这些更改之后清理
您的 Xcode 项目。
关于react-native - 如何更新 rnfirebase admob 以支持 iOS 14 AppTrackingTransparency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67254603/
我是一名优秀的程序员,十分优秀!