Customize In-App message with UAInAppMessageAdapterProtocol

Hi,

I'm trying to customize the In-App Message so it adapts to our App popups, banners e.t.c. so i've made a class that adapts to the UAInAppMessageAdapterProtocol, though the documentation is really lacking on Swift I got it working. I kinda want to know if this approach is correct:

Code:

class UACustomBannerMessage: NSObject, UAInAppMessageAdapterProtocol {

  required init(Message message: UAInAppMessage) {

    DispatchQueue.main.async {

      if let viewController = UIApplication.shared.keyWindow?.rootViewController,

        let banner: UAInAppMessageBannerDisplayContent = message.displayContent as? UAInAppMessageBannerDisplayContent,

        let messageText = banner.body?.text {

        viewController.showToast(message: messageText) // Triggers our own Toast with our own styling

      }

    }

  }

  static func adapter(for message: UAInAppMessage) -> Self {

    return self.init(Message: message)

  }

  func prepare(_ completionHandler: @escaping (UAInAppMessagePrepareResult) -> Void) {

    print("Preparing for message")

    completionHandler(.success)

  }

  func isReadyToDisplay() -> Bool {

    print("Ready to display!!")

    return true

  }

  func display(_ completionHandler: @escaping (UAInAppMessageResolution) -> Void) {

    completionHandler(.timedOut())

  }

}

 

This code is triggered by implementing:

UAirship.inAppMessageManager()?.setFactoryBlock({ (message) -> UAInAppMessageAdapterProtocol in

      return UACustomBannerMessage(Message: message)

 }, for: .banner)


The toast that's fired when the in-app message arrives:

class ToastView: UIView, Themable {

  @IBOutlet weak var messageLabel: UILabel!

  private var message: String?


  override func awakeFromNib() {

    ThemeManager.shared.addThemable(self)

    messageLabel.text = "toast_message".localized()

  }

  

  func setMessage(Message message: String) {

    messageLabel.text = message

  }




  func applyTheme(_ theme: Theme) {

    self.backgroundColor = theme.primaryColor

    self.messageLabel.font = theme.defaultTextFont

    self.messageLabel.textColor = theme.lightTextColor

  }

}

 

Is this the correct approach, if not what's the best way of customizing the in-app messages? Also I wanted to know how to correctly use the UAInAppMessageResolution for modals and other popup types (the toast is automatically dismissed after 0.5 seconds)

Thx!

 

 

 

Didn't find what you were looking for?

New post

Comments

9 comments

  • Anyone?

    Comment actions Permalink
    0
  • Hello Sebastiaan,

    Thanks for contacting Airship. My name is Chilun from Technical Support here at Airship and I would be happy to help with this.

    May I ask if you can elaborate on what you meant by "adapt" to your own pop-ups? The following link to the github repo may be a closer fit to what you are trying to achieve:

    https://github.com/urbanairship/ios-library/blob/2e96b644585e85cab8b9db07d98590ac09e7d9db/AirshipKit/AirshipKitTests/UAInAppMessageResolutionEventTest.m

    Kind regards,
    Chilun Liu
    Senior Technical Support Engineer
    Airship

    The Embassy Tea House, 195-205 Union Street, London, SE1 0LN
    Portland | San Francisco | London | Paris | New York | New Delhi

    Comment actions Permalink
    0
  • Hi Chilun,

    What I meant is instead of showing the default Airship popups and banners we want to show our own custom popups and banners which fit the design of our app. The documentation contains Objective-c code but not Swift would be nice if that was updated. I converted the Objective-c code to Swift but I'm not sure if I did everything correctly.

    Kind regards,

    Sebastiaan

    Comment actions Permalink
    0
  • Hello Sebastiaan,

    I see what you mean now :)

    If it works for you then I don't see why you would change this approach. I will need to consult with my colleagues who manage the documentation to update the content on there as it does seem that it should be updated to Swift.

    Thank you for the feedback.

    Kind regards,
    Chilun Liu
    Senior Technical Support Engineer
    Airship

    The Embassy Tea House, 195-205 Union Street, London, SE1 0LN
    Portland | San Francisco | London | Paris | New York | New Delhi

     

    Comment actions Permalink
    0
  • Hi Chilun,

    It works fine for the Banner since it's automatically dismissed. But I don't really get how to do the modal and use the UAInAppMessageResolution correctly? Can you provide an example for that?

    Kind regards,

    Sebastiaan

    Comment actions Permalink
    0
  • Hi Sebastiaan,

    Can you post a link to the documentation what contains details of UAInAppMessageResolution?

    Kind regards,
    Chilun Liu
    Senior Technical Support Engineer
    Airship

    The Embassy Tea House, 195-205 Union Street, London, SE1 0LN
    Portland | San Francisco | London | Paris | New York | New Delhi

    Comment actions Permalink
    0
  • Hi Chilun,

    So the only documentation I found mentioning the UAInAppMessageResolution is on the following link in the Custom Adapters part:
    https://docs.airship.com/platform/ios/in-app-automation/

    Basically everything else I had to figure out using the API references.

    Kind regards,

    Sebastiaan

    Comment actions Permalink
    0
  • Hi Sebastiaan,

    I have now compiled and sent off a report to my colleagues who manage the documentation content. They will continue to investigate this on your behalf. 

    Kind regards,

    Chilun Liu
    Senior Technical Support Engineer
    Airship

    The Embassy Tea House, 195-205 Union Street, London, SE1 0LN
    Portland | San Francisco | London | Paris | New York | New Delhi

    Comment actions Permalink
    0
  • Hello Sebastiaan,

    May I ask if you can now access this link?

    https://docs.airship.com/platform/ios/in-app-automation/?swift#

    My colleagues have now added some additional content to the documentation website for SWIFT :)

    Kind regards,
    Chilun Liu
    Senior Technical Support Engineer
    Airship

    The Embassy Tea House, 195-205 Union Street, London, SE1 0LN
    Portland | San Francisco | London | Paris | New York | New Delhi

    Comment actions Permalink
    0

Please sign in to leave a comment.