prebid / prebid-mobile-ios

Prebid Mobile SDK for iOS applications
Apache License 2.0
46 stars 85 forks source link

938 Fixed Device UA being empty on First Bid Request #957

Closed jsligh closed 3 months ago

jsligh commented 4 months ago

Fixes #938

Removes the race condition and uses UIWebView instead of WKWebView. UIWebView does javascript calls synchronously while WKWebView does javascript asynchronously which is why the race condition is occurring. While synchronous execution might take an extra second, it prevents a lot of headaches and dispatch_once makes sure this only happens once. The UserAgent is also cached in the shared PBMUserAgentService.

jsligh commented 4 months ago

Issue:

I am actually quite stumped on this because of the following:

The current implementation MUST include a completion handler in WKWebView.evaluateJavascript but we can't wait for it to complete because synchronously waiting on the main thread will block the completion handler from ever executing.

self.userAgent = [self.webView valueForKey:@"userAgent"]; while synchronous, is an undocumented API which we cannot guarantee will always work/be correct.

We cannot use ASYNC AWAIT or a similar concurrent Swift function as it is too new (iOS 15+). This will not work as the minimum target version for GMA SDK is iOS 12.0.

Proposed Solutions:

  1. Convert PBMUserAgentService to Swift and use ASYNC AWAIT for clients > iOS 15.0 and keep the current method for clients on older versions.

    • Pushback: doesn't solve problem for users on anything previous to iOS 15.0 (release date 9/20/2021).
  2. Rewrite implementation and put in some kind of wait for all clients.

    • Pushback: could make the code unnecessarily complicated and cause a slowdown on the initialization of PBMUserAgentService.