@@ -306,44 +306,82 @@ + (NSString*)md5:(NSString *)text {
306
306
return NULL ;
307
307
}
308
308
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" ];
310
312
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" ];
318
314
}
319
315
320
316
+ (NSDictionary *)getPushTitleBody : (NSDictionary *)messageDict {
321
317
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
+
323
324
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" ];
328
332
}
329
333
330
- if (!title)
331
- title = messageDict[@" os_data" ][@" buttons" ][@" m" ][@" title" ];
332
334
if (!title)
333
335
title = [[[NSBundle mainBundle ] infoDictionary ] objectForKey: (id )kCFBundleNameKey ];
334
336
if (!title)
335
337
title = @" " ;
336
338
337
339
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 ]])
340
363
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
+
343
381
if (!body)
344
382
body = @" " ;
345
383
346
- return @{@" title" : title, @" body" : body};
384
+ return @{@" title" : title, @" subtitle " : subtitle, @" body" : body};
347
385
}
348
386
349
387
// Prevent the OSNotification blocks from firing if we receive a Non-OneSignal remote push
@@ -408,7 +446,7 @@ + (UILocalNotification*)createUILocalNotification:(NSDictionary*)data {
408
446
409
447
Class UIMutableUserNotificationActionClass = NSClassFromString (@" UIMutableUserNotificationAction" );
410
448
NSMutableArray * actionArray = [[NSMutableArray alloc ] init ];
411
- for (NSDictionary * button in data[ @" o " ]) {
449
+ for (NSDictionary * button in [OneSignalHelper getActionButtons: data ]) {
412
450
id action = [[UIMutableUserNotificationActionClass alloc ] init ];
413
451
[action setTitle: button[@" n" ]];
414
452
[action setIdentifier: button[@" i" ] ? button[@" i" ] : [action title ]];
@@ -428,9 +466,10 @@ + (UILocalNotification*)createUILocalNotification:(NSDictionary*)data {
428
466
NSUInteger notificationTypes = NOTIFICATION_TYPE_ALL;
429
467
430
468
NSSet * currentCategories = [[[UIApplication sharedApplication ] currentUserNotificationSettings ] categories ];
431
- if (currentCategories)
469
+ if (currentCategories)
432
470
currentCategories = [currentCategories setByAddingObject: category];
433
- else currentCategories = [NSSet setWithObject: category];
471
+ else
472
+ currentCategories = [NSSet setWithObject: category];
434
473
435
474
[[UIApplication sharedApplication ] registerUserNotificationSettings: [uiUserNotificationSettings settingsForTypes: notificationTypes categories: currentCategories]];
436
475
notification.category = [category identifier ];
@@ -509,7 +548,7 @@ + (id)prepareUNNotificationRequest:(NSDictionary *)data :(NSDictionary *)userInf
509
548
return NULL ;
510
549
511
550
NSMutableArray * actionArray = [[NSMutableArray alloc ] init ];
512
- for (NSDictionary * button in data[ @" o " ]) {
551
+ for (NSDictionary * button in [OneSignalHelper getActionButtons: data ]) {
513
552
NSString * title = button[@" n" ] != NULL ? button[@" n" ] : @" " ;
514
553
NSString * buttonID = button[@" i" ] != NULL ? button[@" i" ] : title;
515
554
id action = [NSClassFromString (@" UNNotificationAction" ) actionWithIdentifier: buttonID title: title options: UNNotificationActionOptionForeground ];
@@ -528,28 +567,10 @@ + (id)prepareUNNotificationRequest:(NSDictionary *)data :(NSDictionary *)userInf
528
567
id content = [[NSClassFromString (@" UNMutableNotificationContent" ) alloc ] init ];
529
568
[content setValue: @" __dynamic__" forKey: @" categoryIdentifier" ];
530
569
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" ];
553
574
554
575
[content setValue: userInfo forKey: @" userInfo" ];
555
576
0 commit comments