SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.32k stars 746 forks source link

SwiftMessages.hide() removing all messages in queue from versions 8.0.4 to 9.0.0 for iPad, But not for iPhone #465

Closed vishnu-devineni closed 3 years ago

vishnu-devineni commented 3 years ago

Hi,

I am using SwiftMessages in our Project. I am showing two type of Toast messages, one is with a text and other one is with a text and having a button to dismiss the toast. Previously I were using 7.0.1 and recently I upgraded to 9.0.0

From there onwards, If I click on the Dismiss button (which will call SwiftMessages.hide()), I am not getting any messages that are in the queue, for iPad, But on iPhone, everything is working fine. The same code has been used for iPhone and iPad.

Even though if I remove the toast messages with a swipe towards the bottom of the screen, I am not getting next toast messages which are added to the queue.

If I did not remove the toast messages (waiting for 4 seconds for every toast message) with dismiss button or with swipe to bottom (default SwiftMessages feature) then I am getting all the messages that are added to the queue.

public func Toast (text: String?, delay: TimeInterval? = 0.0, duration: TimeInterval? = 4.0, height: CGFloat = 0, shouldAddButton: Bool = false, buttonTitle: String? = nil) {

        DispatchQueue.main.async {
            let messageView = MessageView.viewFromNib(layout: .cardView)
            messageView.configureTheme(.success)
            messageView.button?.isHidden = !shouldAddButton
            messageView.iconImageView?.isHidden = true
            messageView.titleLabel?.isHidden = true
            messageView.configureContent(body: text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "")

            messageView.layoutMarginAdditions = UIEdgeInsets(top: 20, left: 20, bottom: 110, right: 20)
            (messageView.backgroundView as? CornerRoundingView)?.cornerRadius = 5
            messageView.layer.masksToBounds = true
            messageView.backgroundView.backgroundColor = .gray
            messageView.configureDropShadow()
            messageView.bodyLabel?.textColor = .white

            if shouldAddButton {
                messageView.button?.setTitleColor(.white, for: .normal)
                messageView.button?.backgroundColor = .clear                
                messageView.configureContent(title: nil, body: text, iconImage: nil, iconText: nil, buttonImage: nil, buttonTitle: buttonTitle) { (_) in
                    SwiftMessages.hide()
                }

            } else {
                messageView.configureContent(body: text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "")
            }

            var messageConfig = SwiftMessages.Config()
            messageConfig.presentationStyle = .bottom
            messageConfig.duration = .seconds(seconds: duration ?? 4.0)
            messageConfig.ignoreDuplicates = false

            SwiftMessages.pauseBetweenMessages = 1.0
            SwiftMessages.show(config: messageConfig, view: messageView)
    }
}

I have tried versions 9.0.1 and 9.0.2, But I am not getting any Toast messages for the same code where the below versions are showing me toast messages

I have verified all the versions from 7.0.1 to 9.0.0 I noticed 8.0.0, 8.0.2 and 8.0.3 are working fine for me, which means the same above code is working great even If I dismiss the toast (SwiftMessages.hide()) it is showing all other messages that are in the queue.

Please help me how to fix this issue.

wtmoose commented 3 years ago

It sounds a lot like #458, which was fixed in 9.0.1. The problem was that if you interact with the toast view, the key window changes and iOS doesn't automatically restore the key window when you dismiss the toast. 9.0.1 added logic to restore the key window to the previous value.

In the past, folks have reported problems and it turned out that they just needed to clean their workspace. Can you try cleaning and verify if it still doesn't work for you?

vishnu-devineni commented 3 years ago

@wtmoose Thanks for the immediate response, As I informed, I am not seeing any Toast message View in versions 9.0.1 and 9.0.2

I am using Carthage to use SwiftMessages and my cart file is having the below line.

github "SwiftKickMobile/SwiftMessages" == 9.0.2

I use to delete derived data every day and I use to clean build folder every day (cmd+shft+option+k).

I have deleted the build folder in my carthage folder of my project, so that it will build freshly. But I did not tested yet because of some personal work.

I will delete my existing carthage folder and do a carthage update tomorrow morning and will update you after testing. If I need to do any other changes to clean my workspace, please let me know. I will update you tomorrow morning which is after 10 hours from now.

vishnu-devineni commented 3 years ago

@wtmoose

I have deleted my Carthage folder and derived data, Still, I am not getting any Toast messages in 9.0.2

Could you please check each and every line above and let me know what else I missed for the new version

I have added the below code as well which is not there in the above code

messageConfig.presentationContext = .window(windowLevel: .statusBar) // (tried with automatic and other window levels)
messageConfig.preferredStatusBarStyle = .lightContent
messageConfig.interactiveHide = false

Even I tried all the theme modes like warning, error, success and info for messageView.configureTheme.

Still I am not seeing any Toast messages in 9.0.2 version

Could you please help me, how can I fix my issue

wtmoose commented 3 years ago

I wasn't able to reproduce your problem using the code you supplied. Here's my test project.

SwiftMessagesTest.zip

Can you supply a test project that demonstrates the problem? Or try stepping through the show() function in the debugger and letting me know where it fails?

vishnu-devineni commented 3 years ago

Thank you very much for your response.

I will go through you test project and I will also share a test app in a while. I will try to add your library and will debug on show() function that i am using and let you know.

wtmoose commented 3 years ago

A good starting point for debugging is line 598 in SwiftMessages.swift. You can put a breakpoint there and determine if the system is trying to show the messages or not. From there you can trace forward or backward to find out where things go wrong.

try current.show { completed in
    guard let strongSelf = self else { return }
    guard completed else {
        strongSelf.messageQueue.sync {
            strongSelf.internalHide(presenter: current)
        }
        return
    }
    if current === strongSelf.autohideToken {
        strongSelf.queueAutoHide()
    }
}
vishnu-devineni commented 3 years ago

Thanks for guiding me in the right way.

But If we added the library for debugging, we are able to get the toast messages and queue mechanism also working absolutely fine in iPad with 9.0.2

FYI, If I create a sample app with cocoapods, Toast messages are working without any issue. But I have created a sample project with carthage and I am not getting any Toast messages (I have attached the sample project). I can't debug the app since, If I added the library for debugging, Toast messages are working without any issues.

I have verified your sample app and it is working absolutely fine for me. But It is having the SwiftMessages source code and so Toast messages are working fine. But If we add swiftMessages as a carthage library (which we can't debug the framework) then we are not seeing any toast messages.

FYI, I have added the SwiftMessages source code to my project for debugging and I am able to see Toast messages without having any issues.

Could you please check the attached sample project and let me know the issue possiblities.

Deleting my sample code since you already downloaded

wtmoose commented 3 years ago

I see what the problem is. I changed the iMessageDemo project to use CocoaPods in 9.0.2 because there was a problem related to app exetensions + Cocapods.

Carthage is building the Cocoapods SwiftMesages framework build for app extensions, which won't work correctly in an app.

*** xcodebuild output can be found in /var/folders/mc/662grfnx6cnc_v7tj0prjs7w0000gn/T/carthage-xcodebuild.hPBOIW.log
*** Building scheme "SwiftMessages" in iMessageDemo.xcworkspace

You should be able to delete the iMessageDemo folder from the Carthage checkout as a workaround until I figure out a fix.

vishnu-devineni commented 3 years ago

Thanks for finding the issue. We will use the version 8.0.3 for now. We will wait for your fix and new version, to update our project's SwiftMessages version

wtmoose commented 3 years ago

@vishnu-devineni I apologies for taking so long to fix this. I was swamped at work. This was pretty annoying issue to figure out, but I think it is solved on branch work/9.0.3 if you want to try it. You may need to go into the iMessageDemo folder and run pod install, if you have CocoaPods installed, or manually delete the folder iMessageDemo/Pods/Pods.xcodeproj/xcuserdata.