Is UMPConsentForm:presentFromViewController not synchronous?

225 views
Skip to first unread message

Emmanuel

unread,
Dec 20, 2023, 7:40:19 PM12/20/23
to Google Mobile Ads SDK Developers
I am running into an issue displaying the consent form in an iOS objective C app.

In this app, user interactions can lead to a UIAlertController being presented and dismissed at any time.

It is clear that UMPConsentForm:loadAndPresentIfRequiredFromViewController is not synchronous in the sense that UI events are being processed on the main loop while the form is being loaded. The viewController passed in may no longer be the active UIViewController by the time the SDK calls presentViewController on it.

My solution was to use loadWithCompletionHandler and, in that completion handler, call the UMPConsentForm's presentFromViewController method with the active viewController at that time. To my surprise, I am still seeing occasional race conditions where the active view controller at the time I call UMPConsentForm:presentFromViewController is no longer the  active controller by the time that method calls presentViewController on it.

I think we need an API to present a consent form immediately and synchronously on a given viewController before subsequent user interactions can cause changes to the view controller hierarchy. Is there a way to do this? In an iOS Objective C app?

Thanks,
Emmanuel

Mobile Ads SDK Forum Advisor

unread,
Dec 20, 2023, 8:52:53 PM12/20/23
to a...@mindthefrog.com, google-adm...@googlegroups.com

Hi Emmanuel,

Thank you for contacting the Mobile Ads SDK Support team.

I will check with our team regarding your query and one of my team members will reach out to you once we have an update on this. Meanwhile, your patience is highly appreciated.
 

This message is in relation to case "ref:!00D1U01174p.!5004Q02r30Js:ref"

Thanks,
 
Google Logo Mobile Ads SDK Team


Ibral Ansari

unread,
Dec 21, 2023, 3:55:13 AM12/21/23
to Google Mobile Ads SDK Developers
Yes

Ibral Ansari

unread,
Dec 21, 2023, 3:56:47 AM12/21/23
to Google Mobile Ads SDK Developers
On Thursday, December 21, 2023 at 4:52:53 AM UTC+3 Mobile Ads SDK Forum Advisor wrote:
129613652-IMG-20231112-WA0006.jpg

Mobile Ads SDK Forum Advisor

unread,
Dec 26, 2023, 11:57:28 AM12/26/23
to a...@mindthefrog.com, google-adm...@googlegroups.com
Hi Emmanuel,

Do you have a screen recording of your iOS app that showcase this race condition?

The UMP SDK calls presentViewController which according to the documentation, may not be the view controller that handles the presentation. 

"The object on which you call this method may not always be the one that handles the presentation. Each presentation style has different rules governing its behavior. For example, a full-screen presentation must be made by a view controller that itself covers the entire screen. If the current view controller is unable to fulfill a request, it forwards the request up the view controller hierarchy to its nearest parent, which can then handle or forward the request."

Thanks,
Justin

ref:!00D1U01174p.!5004Q02r30Js:ref

Emmanuel

unread,
Dec 26, 2023, 9:20:42 PM12/26/23
to Google Mobile Ads SDK Developers
Thanks Justin.

Let's say you have a root view controller (RVC) and a UIAlertViewController popup (AVC) presented with RVC.presentViewController(AVC).

UMPConsentForm's presentFromViewController(RVC) and loadAndPresentIfRequiredFromViewController(RVC) can fail and call the completion handler with error set to "The provided view controller is already presenting another view controller".

Furthermore, if you call consentForm.presentFromViewController(AVC) *while* AVC is being dismissed (via dismissViewController) with an animation, the operation silently fails. The completion handler is not called. This error message is printed to the console: "Attempt to present <UMPConsentViewController: 0xXXXXXXXXX> on <UIAlertController: 0xXXXXXXXXX> (from <UIAlertController: 0xXXXXXXXXX>) whose view is not in the window hierarchy."

It turns out it's the latter race condition that is causing me headaches. In my testing, consentForm.presentFromViewController is synchronous, so that's not the issue.

It's messy but it's possible to check AVC.isBeingDismissed and in that case, delay calling consentForm.presentFromViewController until after the dismiss animation has completed. I assume it's ok to hold a reference on consentForm to do this?

But... is there a simpler way?

Mobile Ads SDK Forum Advisor

unread,
Dec 27, 2023, 12:35:09 PM12/27/23
to a...@mindthefrog.com, google-adm...@googlegroups.com
Hello,

At this time, based on your app's implementation (the unpredictability of presenting and dismissing view controllers), there does not appear to be a simpler way. It is okay hold a reference on consentForm just be sure to release the reference to avoid a memory leak.
Reply all
Reply to author
Forward
0 new messages