Comments (3)
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.
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.
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)
- Carthage Support
- Banner hidden by iPhone X notch
- Messages go above navigation bar (iOS 14)
- When there is SceneDelegate in app then it won't showing TWMessageBar
- Turn png images to code using PaintCode HOT 1
- Customization HOT 6
- Dismiss via swipe HOT 3
- Text is vertically not centered HOT 1
- Vertically align label with icon when description == nil or title == no HOT 1
- Swift support? HOT 1
- description not align icon HOT 1
- Swift Project HOT 2
- Some change to your project. HOT 1
- Allow to setup windowLevel
- use_frameworks! HOT 4
- Banner does not show in case of multiple push notification. HOT 1
- callback block not executed HOT 6
- Issue - Alert bellow status bar in iOS 9/10 HOT 1
- Customize TWMessageView numerics
- Do not hide, keep the popup unless until user taps on it? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twmessagebarmanager.