SwiftKickMobile/SwiftMessages

Messages stop showing after user interacts (taps or dismisses) one of them

SethForsgren opened this issue · 10 comments

I'm using SwiftMessages to alert the user to a new message from a coworker. The code below is called each time a user receives a notification. It works great until the user interacts with the SwiftMessage. Once they either tap on it, or dismiss it by dragging it up, then no more SwiftMessages are presented until the user navigates to a different view within our app itself.

I'd like new SwiftMessages to keep showing up even if the user dismisses or taps on one in their current view. Any ideas on how to achieve this?

How I'm calling show() currently:

public func showInAppMessageNotification(content: UNMutableNotificationContent) {
  // Hide the previous message if any is being shown currently
  SwiftMessages.hide(animated: false)
  
  // Ensure no delay in showing subsequent messages
  SwiftMessages.pauseBetweenMessages = 0.0
  
  // configure messages to show if same user repeatedly sends messages
  var config = SwiftMessages.Config()
  config.ignoreDuplicates = false
  
  // Instantiate a message view from the centeredview layout in resources
  let view = MessageView.viewFromNib(layout: .centeredView)
  
  // Set message title, body
  view.configureContent(title: content.title, body: content.body)

  // Increase the external margin around the card
  view.layoutMarginAdditions = UIEdgeInsets(top: 8, left: 72, bottom: 0, right: 72)

  // Reduce the corner radius
  (view.backgroundView as? CornerRoundingView)?.cornerRadius = 14
  
  // React when message view is tapped by navigating to the right channel view in our app
  view.tapHandler = {
    _ in
    
    let fromChannelID = content.userInfo["channelID"] as! String
    transitionToTappedChannel(fromChannelID: fromChannelID)
    
    SwiftMessages.hide()
  }

  // Show the message
  SwiftMessages.show(config: config, view: view)
}

There was a bug in 8.0.4 that could cause this issue. What version are you on? #444

thanks for the quick reply. I'm running 9.0.0 currently.

I'll try and take a look at any differences between 8.0.4 and 8.0.5 perhaps. Lmk if other details could help debug.

I created a test app that demonstrates this issue: https://github.com/SethForsgren/SM-testing

It has 2 buttons on the main screen:

When tapping "Show Message Once" => message always appears

When tapping "Show Message Once, and again in 3 seconds" => if you dismiss the first message within 3 seconds by tapping on it or dragging it away, then the second message does not present on screen. If you don't interact with the first message, then the second one will appear.

Ideally both messages will show whenever tapping "Show Message Once, and again in 3 seconds"

An interesting finding is that if the user taps anywhere on the app screen after dismissing the first message, then the subsequent message will show. The subsequent message is missed if the user interacts with the first message, and then does nothing on the app until the subsequent message is supposed to show up.

One more note in case it helps, I went ahead and tried that sample app with previous versions of SwiftMessages below. The app builds and reproduces the same issue with each.

9.0.0

Commit: 4408c09

8.0.5

Commit: 243fa75

8.0.4

Commit: f7297cc

Thanks for making this so easy to troubleshoot. Could you try out the branch work/9.0.1?

Basically, in cases where the message is displayed in a separate window, that window may become the key window, like if you interact with it. iOS doesn't automatically restore the previous key window when you dismiss the message. So, the WindowViewController class in SM tries to automatically restore the key window for you, but that logic wasn't particularly robust. Hopefully my fix covers all of the cases.

That branch works perfectly, thank you for the quick update!

I will use that work/9.0.1 branch now unless you want to merge it into main.

For reference, I swapped 9.0.0 for work/9.0.1 commit: eeb6853

Don't merge into main. I have a major 10.0.0 under development on main (forgot to put it on a work branch).

I'll release a 9.0.1 patch after I get chance to see if there are any other small changes I need to get in.

Sounds good. I will keep an eye out for the patch.

9.0.1 is released