cruffenach / CRToast

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

Action tap #173

Closed iMark21 closed 9 years ago

iMark21 commented 9 years ago

Is it possible to add an action launcher when tap the notification?

jadar commented 9 years ago

By action launcher I assume you mean a callback or selector call?

What you can do is set up a CRToastInteractionResponder that will call your own method. That would look something like this:

[CRToastManager showNotificationWithOptions:@{
    kCRToastInteractionRespondersKey: @[CRToastInteractionResponder  interactionResponderWithInteractionType: CRToastInteractionTypeTap automaticallyDismiss:NO block:^{
        // your code
    }]]
} 
                             appearanceBlock:nil
                             completionBlock:nil];
Ashton-W commented 9 years ago

Thanks @jadar.

Please re-open if that doesn't answer your question.

iMark21 commented 9 years ago

Thanks @jadar but using your solution I'm getting the next issue: "Unexpected interface name 'CRToastInteractionResponder' expectede expression, ...

NSDictionary *options = @{ kCRToastTextKey : messageTitleToast, kCRToastTextColorKey : [UIColor darkGrayColor], ... }

I only need the key and the value to add to the dictionary options to CRToastManager. Any clue?

Thank you!!

jadar commented 9 years ago

It looks like maybe you're doing this in the wrong place.. http://stackoverflow.com/questions/7375292/what-is-unexpected-interface-name-in-objective-c-iphone-development

In terms of keys and values, this might help to show you how to add an interaction responder better..

CRToastInteractionResponder *responder = [CRToastInteractionResponder interactionResponderWithInteractionType:CRToastInteractionTypeTap
                                                                                         automaticallyDismiss:NO
                                                                                                        block:^{
                                                                                                            // your interaction code.
                                                                                                        }];
NSDictionary *options = @{
                          kCRToastInteractionRespondersKey : @[responder]
                         }
iMark21 commented 9 years ago

Yeah! It works!! thank you @jadar