GithubHelp home page GithubHelp logo

Comments (3)

terryworona avatar terryworona commented on June 2, 2024

I'd rather keep the control mutually exclusive of any single use-case. Your code above is half-way there to having it absorb remote (or local) notifications; I don't really want to bake that into the current implementation.

from twmessagebarmanager.

cannyboy avatar cannyboy commented on June 2, 2024

Well, I think a message bar which can deal with push notifications would be pretty useful.

Here's a quick hack which i haven't thoroughly tested. It uses the "loc-args" & "loc-key" parameters of the userInfo dictionary. A better way would be to work out what kind of notification format the JSON is and deal with it appropriately. Examples are at the bottom of this page: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
(for instance, is the 'alert' key an array or string?)

- (void)showMessageWithTitle:(NSString*)title userInfo:(NSDictionary*)userInfo type:(MessageBarMessageType)type duration:(CGFloat)duration callback:(void (^)())callback
{

    NSString *arg1 = @"";
    NSString *arg2 = @"";
    NSString *arg3 = @"";
    NSString *arg4 = @"";

    int i = 0;
    for (NSString *arg in userInfo[@"aps"][@"alert"][@"loc-args"]) {
        switch (i) {
            case 0:
                arg1 = arg;
                break;
            case 1:
                arg2 = arg;
                break;
            case 2:
                arg3 = arg;
                break;
            case 3:
                arg4 = arg;
                break;
            default:
                break;
        }
        i++;
    }
    NSString *localizedStringKey = userInfo[@"aps"][@"alert"][@"loc-key"];
    NSString *description = [NSString stringWithFormat:NSLocalizedString(localizedStringKey, nil), arg1, arg2, arg3, arg4];


    MessageView *messageView = [[MessageView alloc] initWithTitle:title description:description type:type];

    messageView.callbacks = callback ? [NSArray arrayWithObject:callback] : [NSArray array];
    messageView.hasCallback = callback ? YES : NO;

    messageView.duration = duration;
    messageView.hidden = YES;

    [[[UIApplication sharedApplication] keyWindow] insertSubview:messageView atIndex:1];
    [self.messageBarQueue addObject:messageView];

    if (!self.messageVisible)
    {
        [self showNextMessage];
    }
}

and it can be called with

[[MessageBarManager sharedInstance] showMessageWithTitle:@"Title" userInfo:userInfo
                                                          type:MessageBarMessageTypeInfo
    ];

from twmessagebarmanager.

terryworona avatar terryworona commented on June 2, 2024

Like I said, I want the control to remain decoupled from any single use case (ie. remote notifications, reachability, etc).

Your code looks great, and you should absolutely use it to support remote notification messages, I just don't think it belongs in the library.

I would recommend subclassing the manager or putting it into a category (ie. MessageBarManager+Notifications).

from twmessagebarmanager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.