@@ -68,30 +68,32 @@ @implementation OSNotificationPayload
6868
6969- (id )initWithRawMessage : (NSDictionary *)message {
7070 self = [super init ];
71- if (self && message) {
72- _rawPayload = [NSDictionary dictionaryWithDictionary: message];;
71+ if (self && message) {
72+ _rawPayload = [NSDictionary dictionaryWithDictionary: message];
7373
74- if (_rawPayload[@" aps" ][@" content-available" ])
74+ if (_rawPayload[@" aps" ][@" content-available" ])
7575 _contentAvailable = (BOOL )_rawPayload[@" aps" ][@" content-available" ];
76- else _contentAvailable = NO ;
76+ else
77+ _contentAvailable = NO ;
7778
78- if (_rawPayload[@" aps" ][@" badge" ])
79+ if (_rawPayload[@" aps" ][@" badge" ])
7980 _badge = (int )_rawPayload[@" aps" ][@" badge" ];
8081 else _badge = (int )_rawPayload[@" badge" ];
8182
8283 _actionButtons = _rawPayload[@" o" ];
83- if (!_actionButtons)
84+ if (!_actionButtons)
8485 _actionButtons = _rawPayload[@" os_data" ][@" buttons" ][@" o" ];
8586
8687 if (_rawPayload[@" aps" ][@" sound" ])
8788 _sound = _rawPayload[@" aps" ][@" sound" ];
8889 else if (_rawPayload[@" s" ])
8990 _sound = _rawPayload[@" s" ];
90- else _sound = _rawPayload[@" os_data" ][@" buttons" ][@" s" ];
91+ else
92+ _sound = _rawPayload[@" os_data" ][@" buttons" ][@" s" ];
9193
9294 if (_rawPayload[@" custom" ]) {
9395 NSDictionary * custom = _rawPayload[@" custom" ];
94- if (custom[@" a" ])
96+ if (custom[@" a" ])
9597 _additionalData = [custom[@" a" ] copy ];
9698 _notificationID = custom[@" i" ];
9799 _launchURL = custom[@" u" ];
@@ -115,22 +117,23 @@ - (id)initWithRawMessage:(NSDictionary*)message {
115117
116118 if (_rawPayload[@" m" ]) {
117119 id m = _rawPayload[@" m" ];
118- if ([m isKindOfClass: [NSDictionary class ]]) {
120+ if ([m isKindOfClass: [NSDictionary class ]]) {
119121 _body = m[@" body" ];
120122 _title = m[@" title" ];
121123 _subtitle = m[@" subtitle" ];
122124 }
123- // Content-only
124- else _body = m;
125+ else
126+ _body = m;
125127 }
126128 else if (_rawPayload[@" aps" ][@" alert" ]) {
127129 id a = message[@" aps" ][@" alert" ];
128- if ([a isKindOfClass: [NSDictionary class ]]) {
130+ if ([a isKindOfClass: [NSDictionary class ]]) {
129131 _body = a[@" body" ];
130132 _title = a[@" title" ];
131133 _subtitle = a[@" subtitle" ];
132134 }
133- else _title = a;
135+ else
136+ _body = a;
134137 }
135138 else if (_rawPayload[@" os_data" ][@" buttons" ][@" m" ]) {
136139 NSDictionary * m = _rawPayload[@" os_data" ][@" buttons" ][@" m" ];
@@ -139,6 +142,7 @@ - (id)initWithRawMessage:(NSDictionary*)message {
139142 _subtitle = m[@" subtitle" ];
140143 }
141144 }
145+
142146 return self;
143147}
144148@end
@@ -313,55 +317,61 @@ + (NSArray*)getActionButtons {
313317 return lastMessageReceived[@" o" ];
314318}
315319
316- + (NSArray <NSString*> *)getPushTitleBody : (NSDictionary *)messageDict {
320+ + (NSDictionary *)getPushTitleBody : (NSDictionary *)messageDict {
317321
318322 NSString *title = messageDict[@" m" ][@" title" ];
319- NSString *body = messageDict[@" m" ][@" body" ];
320- if (!title) {
321- if ([messageDict[@" aps" ][@" alert" ] isKindOfClass: [NSDictionary class ]])
323+ if (!title) {
324+ if ([messageDict[@" aps" ][@" alert" ] isKindOfClass: [NSDictionary class ]])
322325 title = messageDict[@" aps" ][@" alert" ][@" title" ];
323- else title = messageDict[@" aps" ][@" alert" ];
326+ else
327+ title = messageDict[@" aps" ][@" alert" ];
324328 }
325329
326- if (!title)
330+ if (!title)
327331 title = messageDict[@" os_data" ][@" buttons" ][@" m" ][@" title" ];
328- if (!title)
332+ if (!title)
329333 title = [[[NSBundle mainBundle ] infoDictionary ] objectForKey: (id )kCFBundleNameKey ];
330- if (!title) title = @" " ;
334+ if (!title)
335+ title = @" " ;
331336
332- if (!body && [messageDict[@" aps" ][@" alert" ] isKindOfClass: [NSDictionary class ]])
337+
338+ NSString *body = messageDict[@" m" ][@" body" ];
339+ if (!body && [messageDict[@" aps" ][@" alert" ] isKindOfClass: [NSDictionary class ]])
333340 body = messageDict[@" aps" ][@" alert" ][@" body" ];
334- if (!body)
341+ if (!body)
335342 body = messageDict[@" os_data" ][@" buttons" ][@" m" ][@" body" ];
336- if (!body)
343+ if (!body)
337344 body = @" " ;
338345
339- return @[ title, body] ;
346+ return @{ @" title" : title, @" body" : body} ;
340347}
341348
342349// Prevent the OSNotification blocks from firing if we receive a Non-OneSignal remote push
343350+ (BOOL )isOneSignalPayload {
344- if (!lastMessageReceived) return NO ;
351+ if (!lastMessageReceived)
352+ return NO ;
345353 return lastMessageReceived[@" custom" ][@" i" ] || lastMessageReceived[@" os_data" ][@" i" ];
346354}
347355
348356+ (void )handleNotificationReceived : (OSNotificationDisplayType)displayType {
349- if (!handleNotificationReceived || ![self isOneSignalPayload ]) return ;
350-
357+ if (!handleNotificationReceived || ![self isOneSignalPayload ])
358+ return ;
351359
352360 OSNotificationPayload *payload = [[OSNotificationPayload alloc ] initWithRawMessage: lastMessageReceived];
353361 OSNotification *notification = [[OSNotification alloc ] initWithPayload: payload displayType: displayType];
354362
355363 // Prevent duplicate calls to same action
356364 static NSString * lastMessageID = @" " ;
357- if ([payload.notificationID isEqualToString: lastMessageID]) return ;
365+ if ([payload.notificationID isEqualToString: lastMessageID])
366+ return ;
358367 lastMessageID = payload.notificationID ;
359368
360369 handleNotificationReceived (notification);
361370}
362371
363372+ (void )handleNotificationAction : (OSNotificationActionType)actionType actionID : (NSString *)actionID displayType : (OSNotificationDisplayType)displayType {
364- if (!handleNotificationAction || ![self isOneSignalPayload ]) return ;
373+ if (!handleNotificationAction || ![self isOneSignalPayload ])
374+ return ;
365375
366376 OSNotificationAction *action = [[OSNotificationAction alloc ] initWithActionType: actionType :actionID];
367377 OSNotificationPayload *payload = [[OSNotificationPayload alloc ] initWithRawMessage: lastMessageReceived];
@@ -370,7 +380,8 @@ + (void)handleNotificationAction:(OSNotificationActionType)actionType actionID:(
370380
371381 // Prevent duplicate calls to same action
372382 static NSString * lastMessageID = @" " ;
373- if ([payload.notificationID isEqualToString: lastMessageID]) return ;
383+ if ([payload.notificationID isEqualToString: lastMessageID])
384+ return ;
374385 lastMessageID = payload.notificationID ;
375386
376387 handleNotificationAction (result);
@@ -484,7 +495,8 @@ + (void)requestAuthorization {
484495
485496+ (void )registerAsUNNotificationCenterDelegate {
486497 Class UNNofiCenterClass = NSClassFromString (@" UNUserNotificationCenter" );
487- if (!UNNofiCenterClass) return ;
498+ if (!UNNofiCenterClass)
499+ return ;
488500
489501 UNUserNotificationCenter *curNotifCenter = [UNNofiCenterClass currentNotificationCenter ];
490502 if (!curNotifCenter.delegate )
@@ -493,7 +505,8 @@ + (void)registerAsUNNotificationCenterDelegate {
493505
494506+ (id )prepareUNNotificationRequest : (NSDictionary *)data : (NSDictionary *)userInfo {
495507
496- if (!NSClassFromString (@" UNNotificationAction" ) || !NSClassFromString (@" UNNotificationRequest" )) return NULL ;
508+ if (!NSClassFromString (@" UNNotificationAction" ) || !NSClassFromString (@" UNNotificationRequest" ))
509+ return NULL ;
497510
498511 NSMutableArray * actionArray = [[NSMutableArray alloc ] init ];
499512 for (NSDictionary * button in data[@" o" ]) {
@@ -515,7 +528,7 @@ + (id)prepareUNNotificationRequest:(NSDictionary *)data :(NSDictionary *)userInf
515528 id content = [[NSClassFromString (@" UNMutableNotificationContent" ) alloc ] init ];
516529 [content setValue: @" __dynamic__" forKey: @" categoryIdentifier" ];
517530
518- if (data[@" m" ]) {
531+ if (data[@" m" ]) {
519532 if ([data[@" m" ] isKindOfClass: [NSDictionary class ]]) {
520533 if (data[@" m" ][@" title" ])
521534 [content setValue: data[@" m" ][@" title" ] forKey: @" title" ];
@@ -524,26 +537,26 @@ + (id)prepareUNNotificationRequest:(NSDictionary *)data :(NSDictionary *)userInf
524537 if (data[@" m" ][@" subtitle" ])
525538 [content setValue: data[@" m" ][@" subtitle" ] forKey: @" subtitle" ];
526539 }
527- else [content setValue: data[@" m" ] forKey: @" body" ];
540+ else
541+ [content setValue: data[@" m" ] forKey: @" body" ];
528542 }
529543
530544 else if (data[@" aps" ][@" alert" ]) {
531- if ([data[@" aps" ][@" alert" ] isKindOfClass: [NSDictionary class ]]) {
545+ if ([data[@" aps" ][@" alert" ] isKindOfClass: [NSDictionary class ]]) {
532546 [content setValue: data[@" aps" ][@" alert" ][@" title" ] forKey: @" title" ];
533547 [content setValue: data[@" aps" ][@" alert" ][@" body" ] forKey: @" body" ];
534548 [content setValue: data[@" aps" ][@" alert" ][@" subtitle" ] forKey: @" subtitle" ];
535549 }
536- else [content setValue: data[@" aps" ][@" alert" ] forKey: @" body" ];
550+ else
551+ [content setValue: data[@" aps" ][@" alert" ] forKey: @" body" ];
537552 }
538553
539554 [content setValue: userInfo forKey: @" userInfo" ];
540555
541- if (data[@" s" ]) {
542-
556+ if (data[@" s" ]) {
543557 id defaultSound = [NSClassFromString (@" UNNotificationSound" ) performSelector: @selector (soundNamed: ) withObject: data[@" s" ]];
544558 [content setValue: defaultSound forKey: @" sound" ];
545559 }
546-
547560 else
548561 [content setValue: [NSClassFromString (@" UNNotificationSound" ) performSelector: @selector (defaultSound )] forKey: @" sound" ];
549562
0 commit comments