Skip to content

Commit

Permalink
Merge pull request #19 from danielemegna/manageLocalizeContent
Browse files Browse the repository at this point in the history
Added support to loc-key notification content
  • Loading branch information
pikacode authored Jan 14, 2017
2 parents 676de8e + a320990 commit af3b5ef
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion EBForeNotification/Classes/EBBannerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ -(void)awakeFromNib{
}
}

-(NSString*) extractContentLabel:(NSDictionary*)userInfo{
NSObject *alertValue = userInfo[@"aps"][@"alert"];

if ([alertValue isKindOfClass:[NSString class]])
return alertValue;


if ([alertValue isKindOfClass:[NSDictionary class]]){
NSString *locKey = ((NSDictionary*)alertValue)[@"loc-key"];
if (locKey != nil)
return NSLocalizedString(locKey,nil);
}

@throw [NSException exceptionWithName:NSInvalidArgumentException
reason:@"aps['alert'] field malformed: it is neither a string nor a dictionary with key 'loc-key'"
userInfo:nil];
}

-(void)setUserInfo:(NSDictionary *)userInfo{
_userInfo = userInfo;
UIImage *appIcon;
Expand All @@ -74,7 +92,7 @@ -(void)setUserInfo:(NSDictionary *)userInfo{
assert(0);
}
self.title_label.text = appName;
self.content_label.text = self.userInfo[@"aps"][@"alert"];
self.content_label.text = [self extractContentLabel:userInfo];
self.time_label.text = EBBannerViewTimeText;
[originWindow makeKeyAndVisible];
if (!self.isIos10) {
Expand Down

0 comments on commit af3b5ef

Please sign in to comment.