@@ -306,44 +306,82 @@ + (NSString*)md5:(NSString *)text {
306306 return NULL ;
307307}
308308
309- + (NSArray *)getActionButtons {
309+ + (NSArray *)getActionButtons : (NSDictionary *)messageDict {
310+ if (messageDict[@" os_data" ] && [messageDict[@" os_data" ] isKindOfClass: [NSDictionary class ]])
311+ return messageDict[@" os_data" ][@" buttons" ][@" o" ];
310312
311- if (!lastMessageReceived) return NULL ;
312-
313- if (lastMessageReceived[@" os_data" ] && [lastMessageReceived[@" os_data" ] isKindOfClass: [NSDictionary class ]]) {
314- return lastMessageReceived[@" os_data" ][@" buttons" ][@" o" ];
315- }
316-
317- return lastMessageReceived[@" o" ];
313+ return messageDict[@" o" ];
318314}
319315
320316+ (NSDictionary *)getPushTitleBody : (NSDictionary *)messageDict {
321317
322- NSString *title = messageDict[@" m" ][@" title" ];
318+ NSString *title;
319+ if ([messageDict[@" aps" ][@" alert" ] isKindOfClass: [NSDictionary class ]])
320+ title = messageDict[@" aps" ][@" alert" ][@" title" ];
321+ else
322+ title = messageDict[@" aps" ][@" alert" ];
323+
323324 if (!title) {
324- if ([messageDict[@" aps" ][@" alert" ] isKindOfClass: [NSDictionary class ]])
325- title = messageDict[@" aps" ][@" alert" ][@" title" ];
326- else
327- title = messageDict[@" aps" ][@" alert" ];
325+ if ([messageDict[@" m" ] isKindOfClass: [NSDictionary class ]])
326+ title = messageDict[@" m" ][@" title" ];
327+ }
328+
329+ if (!title) {
330+ if ([messageDict[@" os_data" ][@" buttons" ][@" m" ] isKindOfClass: [NSDictionary class ]])
331+ title = messageDict[@" os_data" ][@" buttons" ][@" m" ][@" title" ];
328332 }
329333
330- if (!title)
331- title = messageDict[@" os_data" ][@" buttons" ][@" m" ][@" title" ];
332334 if (!title)
333335 title = [[[NSBundle mainBundle ] infoDictionary ] objectForKey: (id )kCFBundleNameKey ];
334336 if (!title)
335337 title = @" " ;
336338
337339
338- NSString *body = messageDict[@" m" ][@" body" ];
339- if (!body && [messageDict[@" aps" ][@" alert" ] isKindOfClass: [NSDictionary class ]])
340+ NSString *subtitle;
341+ if ([messageDict[@" aps" ][@" alert" ] isKindOfClass: [NSDictionary class ]])
342+ subtitle = messageDict[@" aps" ][@" alert" ][@" subtitle" ];
343+ else
344+ subtitle = messageDict[@" aps" ][@" alert" ];
345+
346+ if (!subtitle) {
347+ if ([messageDict[@" m" ] isKindOfClass: [NSDictionary class ]])
348+ subtitle = messageDict[@" m" ][@" subtitle" ];
349+ }
350+
351+ if (!subtitle) {
352+ if ([messageDict[@" os_data" ][@" buttons" ][@" m" ] isKindOfClass: [NSDictionary class ]])
353+ subtitle = messageDict[@" os_data" ][@" buttons" ][@" m" ][@" subtitle" ];
354+ }
355+
356+ if (!subtitle)
357+ subtitle = @" " ;
358+
359+
360+
361+ NSString *body;
362+ if ([messageDict[@" aps" ][@" alert" ] isKindOfClass: [NSDictionary class ]])
340363 body = messageDict[@" aps" ][@" alert" ][@" body" ];
341- if (!body)
342- body = messageDict[@" os_data" ][@" buttons" ][@" m" ][@" body" ];
364+ else
365+ body = messageDict[@" aps" ][@" alert" ];
366+
367+ if (!body) {
368+ if ([messageDict[@" m" ] isKindOfClass: [NSDictionary class ]])
369+ body = messageDict[@" m" ][@" body" ];
370+ else
371+ body = messageDict[@" m" ];
372+ }
373+
374+ if (!body) {
375+ if ([messageDict[@" os_data" ][@" buttons" ][@" m" ] isKindOfClass: [NSDictionary class ]])
376+ body = messageDict[@" os_data" ][@" buttons" ][@" m" ][@" body" ];
377+ else
378+ body = messageDict[@" os_data" ][@" buttons" ][@" m" ];
379+ }
380+
343381 if (!body)
344382 body = @" " ;
345383
346- return @{@" title" : title, @" body" : body};
384+ return @{@" title" : title, @" subtitle " : subtitle, @" body" : body};
347385}
348386
349387// Prevent the OSNotification blocks from firing if we receive a Non-OneSignal remote push
@@ -408,7 +446,7 @@ + (UILocalNotification*)createUILocalNotification:(NSDictionary*)data {
408446
409447 Class UIMutableUserNotificationActionClass = NSClassFromString (@" UIMutableUserNotificationAction" );
410448 NSMutableArray * actionArray = [[NSMutableArray alloc ] init ];
411- for (NSDictionary * button in data[ @" o " ]) {
449+ for (NSDictionary * button in [OneSignalHelper getActionButtons: data ]) {
412450 id action = [[UIMutableUserNotificationActionClass alloc ] init ];
413451 [action setTitle: button[@" n" ]];
414452 [action setIdentifier: button[@" i" ] ? button[@" i" ] : [action title ]];
@@ -428,9 +466,10 @@ + (UILocalNotification*)createUILocalNotification:(NSDictionary*)data {
428466 NSUInteger notificationTypes = NOTIFICATION_TYPE_ALL;
429467
430468 NSSet * currentCategories = [[[UIApplication sharedApplication ] currentUserNotificationSettings ] categories ];
431- if (currentCategories)
469+ if (currentCategories)
432470 currentCategories = [currentCategories setByAddingObject: category];
433- else currentCategories = [NSSet setWithObject: category];
471+ else
472+ currentCategories = [NSSet setWithObject: category];
434473
435474 [[UIApplication sharedApplication ] registerUserNotificationSettings: [uiUserNotificationSettings settingsForTypes: notificationTypes categories: currentCategories]];
436475 notification.category = [category identifier ];
@@ -509,7 +548,7 @@ + (id)prepareUNNotificationRequest:(NSDictionary *)data :(NSDictionary *)userInf
509548 return NULL ;
510549
511550 NSMutableArray * actionArray = [[NSMutableArray alloc ] init ];
512- for (NSDictionary * button in data[ @" o " ]) {
551+ for (NSDictionary * button in [OneSignalHelper getActionButtons: data ]) {
513552 NSString * title = button[@" n" ] != NULL ? button[@" n" ] : @" " ;
514553 NSString * buttonID = button[@" i" ] != NULL ? button[@" i" ] : title;
515554 id action = [NSClassFromString (@" UNNotificationAction" ) actionWithIdentifier: buttonID title: title options: UNNotificationActionOptionForeground ];
@@ -528,28 +567,10 @@ + (id)prepareUNNotificationRequest:(NSDictionary *)data :(NSDictionary *)userInf
528567 id content = [[NSClassFromString (@" UNMutableNotificationContent" ) alloc ] init ];
529568 [content setValue: @" __dynamic__" forKey: @" categoryIdentifier" ];
530569
531- if (data[@" m" ]) {
532- if ([data[@" m" ] isKindOfClass: [NSDictionary class ]]) {
533- if (data[@" m" ][@" title" ])
534- [content setValue: data[@" m" ][@" title" ] forKey: @" title" ];
535- if (data[@" m" ][@" body" ])
536- [content setValue: data[@" m" ][@" body" ] forKey: @" body" ];
537- if (data[@" m" ][@" subtitle" ])
538- [content setValue: data[@" m" ][@" subtitle" ] forKey: @" subtitle" ];
539- }
540- else
541- [content setValue: data[@" m" ] forKey: @" body" ];
542- }
543-
544- else if (data[@" aps" ][@" alert" ]) {
545- if ([data[@" aps" ][@" alert" ] isKindOfClass: [NSDictionary class ]]) {
546- [content setValue: data[@" aps" ][@" alert" ][@" title" ] forKey: @" title" ];
547- [content setValue: data[@" aps" ][@" alert" ][@" body" ] forKey: @" body" ];
548- [content setValue: data[@" aps" ][@" alert" ][@" subtitle" ] forKey: @" subtitle" ];
549- }
550- else
551- [content setValue: data[@" aps" ][@" alert" ] forKey: @" body" ];
552- }
570+ NSDictionary * alertDict = [OneSignalHelper getPushTitleBody: data];
571+ [content setValue: alertDict[@" title" ] forKey: @" title" ];
572+ [content setValue: alertDict[@" subtitle" ] forKey: @" subtitle" ];
573+ [content setValue: alertDict[@" body" ] forKey: @" body" ];
553574
554575 [content setValue: userInfo forKey: @" userInfo" ];
555576
0 commit comments