How I handle admob on iOS 14 about IDFA permission


Ok, so first of all we know that iOS 14 is available on iPhone. Starting from iPhone 6s that's my iPhone to test my app until latest iPhone 12. It's quite fun to see a new update that brings something about IDFA. What's IDFA actually? The source I got from the internet said IDFA is Identifier for Advertisers. So basically The IDFA is used for tracking and identifying a user (without revealing personal information).

It's used by Admob to show ads that's relevant to users. So Apple needs permission from iPhone users to allow third party to track their activity. What if iPhone users doesn't allow it maybe third party cannot show ads and It's bad for us who get paid from advertasing. Maybe in the future there'll be a pop up message in the apps that need to active IDFA before using the app. It's something like on website right now. We can't see the content if we don't disable our adblock plugin.

Fortunately We're lucky enough because Apple will delay Its IDFA changes on iOS 14 until early next year. So we have time to prepare implementation in our App. But actually it's not so hard to implement it. You just need to show the permission before showing ads that I'll explain later. I've done it in my native iOS app and cross platform app that use flutter.

So in iOS native you need to code IDFA permission before ads is shown. For example in my app, I put the IDFA permission in splash screen. So user needs to allow or not the permission. If user has chosen the permission my app will continue the screen. For example in my app is home screen. The code for permission is not too long. 

 

This is an example how I handle IDFA permission. I put it in on viewDidAppear so the permission will load when the screen appears. So you need to have conditional checking to check if the device is on ios 14 or not. If it's not you just pass by the UIViewController. And don't forget to add NSUserTrackingUsageDescription in Info.plist. 

<key>NSUserTrackingUsageDescription</key>

<string>This identifier will be used to deliver personalized ads to you.</string>

And

<key>SKAdNetworkItems</key>
 
<array>
   
<dict>
     
<key>SKAdNetworkIdentifier</key>
     
<string>cstr6suwn9.skadnetwork</string>
   
</dict>
 
</array>

And for flutter app on iOS. It's same with iOS native regarding info.plist. Next You need to upgrade your SDK atleast Google-Mobile-Ads-SDK (~> 7.64). For admob I use plugin called admob_flutter and I use 1.0.0 version. So I don't have to update my Google Mobile Ads SDK, it's automatically updated by the admob_flutter plugin. 

Next I need to call function called Admob.requestTrackingAuthorization(). In my splash screen on Flutter. For example I added it using Future.wait. So It's almost same like I did above on native iOS. I need to wait user to accept the permission. So in flutter there's function called Future.wait, it's waiting async function. And then it will reload the page after waiting async function is finished.

This is the piece of code what I mean :

Widget build(BuildContext context) {
return FutureBuilder<List<Object>>(
future: Future.wait([
Admob.requestTrackingAuthorization(),
]),
builder: (BuildContext context, AsyncSnapshot<List<Object>> snapshot) {

So that's all that I can share I hope I can help you to implement this IDFA permission. Good Luck. Thanks for visiting my simple blog.

Source :

https://developers.google.com/admob/ios/ios14

https://pub.dev/packages/admob_flutter

Popular posts from this blog

How to restart the app with flutter Android and iOS

Missing system image Android Studio solution

How to have ConstraintLayout inside ScrollView and ScrollView inside ConstraintLayout Android