cruffenach / CRToast

A modern iOS toast view that can fit your notification needs
MIT License
4.17k stars 463 forks source link

User interactions to dismiss notification not working #206

Open r-shayestehpour opened 8 years ago

r-shayestehpour commented 8 years ago

I have this swift code:


static func showToast(message: String, type: NetworkToastType, isLong: Bool = false , completion: (() -> Void)! = nil) {

        let v = CRToastInteractionResponder(interactionType: .All, automaticallyDismiss: true) { type in
            CRToastManager.dismissNotification(true)
            print("HELLO!")
        }

        var options : [NSObject: AnyObject] = [
            kCRToastTextKey: message,
            kCRToastFontKey: UIFont(name: "myFont", size: 15)!,
            kCRToastTextAlignmentKey: NSTextAlignment.Center.rawValue,
            kCRToastAnimationInDirectionKey: CRToastAnimationDirection.Top.rawValue,
            kCRToastAnimationOutDirectionKey: CRToastAnimationDirection.Top.rawValue,
            kCRToastInteractionRespondersKey: v
        ]

        options[kCRToastNotificationTypeKey] = isLong ? CRToastType.NavigationBar.rawValue : CRToastType.StatusBar.rawValue

        options[kCRToastTimeIntervalKey] = isLong ? 4.0 : 1.5

        CRToastManager.showNotificationWithOptions(options, completionBlock: completion)
    }

I think the interaction responder should dismiss the notification on any user interaction but not only it does not do that, but also the closure is not called("HELLO is never printed on interactions"). What am I doing wrong?

LucasVanDongen commented 7 years ago

Same problem here.

Turned out it expects an array of responders:

kCRToastInteractionRespondersKey: [interactionResponder!] as NSArray

I think I would prefer an object with settings over a dictionary, in that case the compiler would've yelled at me.

SomersJan commented 7 years ago

@LucasVanDongen

Does this workaround still work, since it doesn't for me (I use obj-c)

SomersJan commented 7 years ago

I can confirm that the solution LucasVanDongen gave works !