firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.67k stars 1.49k forks source link

InAppMessagingDisplayMessage shows incorrect type for imageOnly #8081

Closed fumito-ito closed 3 years ago

fumito-ito commented 3 years ago

[REQUIRED] Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

ImageOnly message shows incorrect message type. It may be a bug of parsing passing data.

Steps to reproduce:

  1. add new message as Image Only message at Firebase Console
  2. send test message
  3. open app with following code

Relevant Code:

class Sample: InAppMessagingDisplay {
    func displayMessage(_ messageForDisplay: InAppMessagingDisplayMessage, displayDelegate: InAppMessagingDisplayDelegate) {
        switch messageForDisplay.type {
        case .banner, .card:
            break
        case .modal:
            print("When set `imageOnly` message at firebase console, message will be received with `modal` type")
        case .imageOnly:
            print("This line will be never called.")
        @unknown default:
            break
        }
    }
}

// at AppDelegate
InAppMessaging.inAppMessaging().messageDisplayComponent = Sample()
google-oss-bot commented 3 years ago

I found a few problems with this issue:

yakovmanshin commented 3 years ago

There’s this issue indeed. I’ve faced it myself, and I think I’ll look into it.

@fumito-ito As a quick fix, you can determine message type by type-casting the messageForDisplay instance, like that:

switch messageForDisplay {
    case let bannerMessage as InAppMessagingBannerDisplay:
        print(bannerMessage)
    case let cardMessage as InAppMessagingCardDisplay:
        print(cardMessage)
    case let imageOnlyMessage as InAppMessagingImageOnlyDisplay:
        print(imageOnlyMessage)
    case let modalMessage as InAppMessagingModalDisplay:
        print(modalMessage)
    default:
        break
}

In fact, that’s the way message type is determined in the original implementation of IAM.

christibbs commented 3 years ago

This is a one-liner fix that will go out with the next release.

Bug is here.

christibbs commented 3 years ago

Thanks for the report @fumito-ito.