cruffenach / CRToast

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

CRToastInteractionResponder crash #214

Closed Xpressive closed 7 years ago

Xpressive commented 7 years ago

After upgrading to Swift 3, my app starts crashing when i add InteractionResponder to notification options. Here is my code:

let responder = CRToastInteractionResponder(interactionType: CRToastInteractionType.tap , automaticallyDismiss: true) { (tapped) in
                   //code
                }
opt[kCRToastInteractionRespondersKey] = [responder]
self.showToastWithOptions(opt as! [String : NSObject])

fileprivate static func showToastWithOptions(_ options: [String: NSObject]) {
        DispatchQueue.main.async {
            CRToastManager.dismissNotification(true)

            CRToastManager.showNotification(options: options, apperanceBlock: {

                }, completionBlock: {
            })
        }

    }

Exception is thrown in this method:

- (NSArray *)gestureRecognizersForInteractionResponder:(NSArray*)interactionResponders {
    NSMutableArray *gestureRecognizers = [@[] mutableCopy];
    for (CRToastInteractionResponder *interactionResponder in [kCRInteractionResponders arrayByAddingObjectsFromArray:interactionResponders]) {
        if (CRToastInteractionResponderIsGenertic(interactionResponder.interactionType)) {
            [gestureRecognizers addObjectsFromArray:CRToastGenericRecognizersMake(self, interactionResponder)];
        } else {
            UIGestureRecognizer *gestureRecognizer = CRToastGestureRecognizerMake(self, interactionResponder);
            gestureRecognizer.delegate = self;
            [gestureRecognizers addObject:gestureRecognizer];
        }
    }
    return [NSArray arrayWithArray:gestureRecognizers];
}

line: if (CRToastInteractionResponderIsGenertic(interactionResponder.interactionType)) {

Any ideas how to fix this?

dmiedema commented 7 years ago

What if, instead of using CRToastInteractionType.tap you try CRToastInteractionType.tap.rawValue in the let responder line. I wonder if maybe it may have to do with not getting the literal value though when it does the check maybe?

Xpressive commented 7 years ago

@dmiedema I'v got an error "Cannot convert value of type 'Int' to expected argument type 'CRToastInteractionType'"

dmiedema commented 7 years ago

I'm not sure then - i'd need to make a test project or something to investigate further. Was hoping it was something simple

Xpressive commented 7 years ago

I have just made checkout to another branch, and checkout back after some time. And now it works! Don't know what to say..