Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

managing push notification payload #58

Closed
wdcurry opened this issue Sep 6, 2014 · 9 comments
Closed

managing push notification payload #58

wdcurry opened this issue Sep 6, 2014 · 9 comments

Comments

@wdcurry
Copy link

wdcurry commented Sep 6, 2014

I read the other issue dealing with handling pushes, and respect the ideal of keeping this clean, but most new apps will have notifications, and as such, one tweak to manage this:

Allow one dictionary param to be set into the TW notice. Have it get sent to the completion so allow us easy access to the required data that the push represents.

I don't see this as diluting the focus at all.. just thinking aloud, determining if this is the way to go, as this is critical for my needs. Cheers.

@terryworona
Copy link
Owner

So you want a dictionary property added to each instance of the message view?

Perhaps I'm misunderstanding the need, but model/payload information shouldn't be included in any view-specific classes; basic MVC.

Model-specific logic can exist outside the "show" call and be referenced within the tap callback. Wouldn't this suffice?

@cdzombak
Copy link

cdzombak commented Sep 7, 2014

I'd be interested in hearing more about the use case here; I suspect there's another way to solve your problem without adding model state to this view.

(For sake of argument, I've been trying for a few minutes to come up with a UIKit API that might provide some sort of precedent for this pattern, but I can't think of any.)

@wdcurry
Copy link
Author

wdcurry commented Sep 7, 2014

I think the use-case is quite standard for moderately complex apps. A push notification is received and processed, while the app is active. The user may or may not want to respond. So we toss out a notice. If the user taps it, we know they are engaging, thus we must act on the payload provided by the original push. I suspect a simple __block dictionary will manage this process. I think i was getting confused between reviewing a bunch of libraries today and had this one mixed with another that centralized responses rather than a local block.

So.. __block the payload dictionary, await the engagement and with the code block use the __block variable.. sound about right? (i am a moderate newbie to this platform)

@terryworona
Copy link
Owner

To re-iterate, model and view should remain mutually exclusive.

A MVC solution:

appDidReceiveRemoteNotification:(id)notification...{
     id payload = notification.payload;
     if (payload.notificationType == type1){
        [[TWMessageBarManager sharedInstance] show... callback:{
            // user clicked - we have all info we need from the payload
            [self presentViewOfType:type1 withPayload:payload];
        }];
    }
}

@wdcurry
Copy link
Author

wdcurry commented Sep 7, 2014

thanks terry, similar to what i described after i explained my brain-fart earlier. Only diff is that i was under the assumption only __block vars are accessible inside of callback blocks?

@terryworona
Copy link
Owner

@wdcurry correct, so just declare a few __block vars prior to presenting the message:

_block NSDictionary *payloadBlock = notification.payload;

@cdzombak
Copy link

cdzombak commented Sep 8, 2014

Only diff is that i was under the assumption only __block vars are accessible inside of callback blocks?

No, __block doesn't have anything to do with accessibility. You can capture variables inside callback blocks without any special notation. See this Stack Overflow answer for some additional explanation.

@wdcurry
Copy link
Author

wdcurry commented Sep 8, 2014

thanks kindly cd.. i enjoy learning something new every day ;)

@cdzombak
Copy link

cdzombak commented Sep 8, 2014

i enjoy learning something new every day ;)

As do I 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants