blaugold / user_messaging_platform

A flutter plugin which provides a Dart API for the User Messaging Platform (UMP) SDK, which is the Consent Management Platform (CMP) SDK provided as part of Google's Funding Choices.
https://pub.dev/packages/user_messaging_platform
MIT License
9 stars 5 forks source link

iOS Exception - partial apply for closure #1 in closure #1 in UserMessagingPlatformPlugin.showConsentForm(_:) + 212 (UserMessagingPlatformPlugin.swift:212) #22

Closed stepanov-standy closed 6 months ago

stepanov-standy commented 6 months ago

I am using the latest version of the library. It was in production only for Android users without issue, 2 days ago I have enabled GDPR message for iOS users and start receiving the following error in Firebase Crashlitics:

Crashed: com.apple.main-thread
0  libswiftCore.dylib             0x389a8 _assertionFailure(_:_:file:line:flags:) + 576
1  Runner                         0x2ecbd4 partial apply for closure #1 in closure #1 in UserMessagingPlatformPlugin.showConsentForm(_:) + 212 (UserMessagingPlatformPlugin.swift:212)
2  Runner                         0x2ea550 thunk for @escaping @callee_guaranteed (@guaranteed Error?) -> () + 4313998672 (<compiler-generated>:4313998672)
3  libdispatch.dylib              0x26a8 _dispatch_call_block_and_release + 32
4  libdispatch.dylib              0x4300 _dispatch_client_callout + 20
5  libdispatch.dylib              0x12998 _dispatch_main_queue_drain + 984
6  libdispatch.dylib              0x125b0 _dispatch_main_queue_callback_4CF + 44
7  CoreFoundation                 0x3720c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
8  CoreFoundation                 0x33f18 __CFRunLoopRun + 1996
9  CoreFoundation                 0x33668 CFRunLoopRunSpecific + 608
10 GraphicsServices               0x35ec GSEventRunModal + 164
11 UIKitCore                      0x22c2b4 -[UIApplication _run] + 888
12 UIKitCore                      0x22b8f0 UIApplicationMain + 340
13 Runner                         0x7048 main + 10 (AppDelegate.swift:10)
14 ???                            0x1c964edcc (Missing)

I see it on almost all iOS versions and different models of devices, so looks like it is something common.

Here is the method that I use:

static void updateConsent(bool resetConsent) async {
    try {
      var info =
          await UserMessagingPlatform.instance.requestConsentInfoUpdate(_buildConsentRequestParameters());

      if (info.consentStatus == ConsentStatus.required) {
        await UserMessagingPlatform.instance.showConsentForm();
      } 

    } on Exception catch (e) {
      print(e.toString());
    }
  }

My try-catch block doesn't help as plugin throws fatal error in the line 212:

extension UMPFormErrorCode: CustomStringConvertible {
    public var description: String {
        switch self {
        case .internal:
            return "internal";
        case .alreadyUsed:
            return "alreadyUsed";
        case .timeout:
            return "timeout";
        case .unavailable:
            return "unavailable";
        @unknown default:
            fatalError() //<-- here
        }
    }
}

Probably the issue can be solved automatically by ugrading this library to the latest UMP 2.1.0? Anyway any suggestions or help is highly appriciated as I had to turn off the plugin on iOS, but after mid of January 2024 GDPR message is required by Google and lack of the message may affect earnings.

blaugold commented 6 months ago

Version 1.3.0 of this package now handles UMPFormErrorCode.invalidViewController, which caused the crash. Let me know if the upgrade to the UMP SDK fixes the issue, or whether invalidViewController now just shows up on the Dart side.

stepanov-standy commented 6 months ago

@blaugold thank you so much for so quick turn around. I should say that the reported by me exception was not on 100% of devices, it is a small percentage of total users. I have upgraded to the 1.3.0 and the problem was fixed. It was my design issue when I request to show consent form several times, that is why I receive this exception as fatal. In a new version of library it is handled properly and I receive:

PlatformException(invalidViewController, The provided view controller is already presenting another view controller., null, null)

I have updated my code to not request a consent form after it was already requested. Thanks one more time!

blaugold commented 6 months ago

@stepanov-standy Great! Thanks for the update.