Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions iOS_SDK/OneSignal/OneSignal.m
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,10 @@ + (void)notificationOpened:(NSDictionary*)messageDict isActive:(BOOL)isActive {
cancelButtonTitle:@"Close"
otherButtonTitles:nil, nil];
// Add Buttons
NSArray *additionalData = [OneSignalHelper getActionButtons];
if (additionalData) {
for(id button in additionalData)
[alertView addButtonWithTitle:button[@"n"]];
NSArray *actionButons = [OneSignalHelper getActionButtons:messageDict];
if (actionButons) {
for(id button in actionButons)
[alertView addButtonWithTitle:button[@"n"]];
}

[alertView show];
Expand Down Expand Up @@ -1016,8 +1016,7 @@ + (void) remoteSilentNotification:(UIApplication*)application UserInfo:(NSDictio
//If buttons -> Data is buttons
//Otherwise if titles or body or attachment -> data is everything
if (data) {

if(NSClassFromString(@"UNUserNotificationCenter")) {
if (NSClassFromString(@"UNUserNotificationCenter")) {
if([[OneSignalHelper class] respondsToSelector:NSSelectorFromString(@"addnotificationRequest::")]) {
SEL selector = NSSelectorFromString(@"addnotificationRequest::");
typedef void(*func)(id, SEL, NSDictionary*, NSDictionary*);
Expand All @@ -1042,9 +1041,10 @@ + (void) remoteSilentNotification:(UIApplication*)application UserInfo:(NSDictio

/* Handle the notification reception*/
[OneSignalHelper lastMessageReceived:userInfo];
if([OneSignalHelper isRemoteSilentNotification:userInfo])
if ([OneSignalHelper isRemoteSilentNotification:userInfo])
[OneSignalHelper handleNotificationReceived:OSNotificationDisplayTypeNone];
else [OneSignalHelper handleNotificationReceived:OSNotificationDisplayTypeNotification];
else
[OneSignalHelper handleNotificationReceived:OSNotificationDisplayTypeNotification];
}

+ (void)processLocalActionBasedNotification:(UILocalNotification*) notification identifier:(NSString*)identifier {
Expand All @@ -1062,7 +1062,8 @@ + (void)processLocalActionBasedNotification:(UILocalNotification*) notification
additionalData = [[NSMutableDictionary alloc] initWithDictionary:customDict[@"a"]];
optionsDict = userInfo[@"o"];
}
else return;
else
return;

NSMutableArray* buttonArray = [[NSMutableArray alloc] init];
for (NSDictionary* button in optionsDict) {
Expand Down Expand Up @@ -1303,7 +1304,7 @@ + (void)load {
return;

injectToProperClass(@selector(setOneSignalUNDelegate:),
@selector(setDelegate:), @[], [sizzleUNUserNotif class], UNUserNotificationCenterClass);
@selector(setDelegate:), @[], [swizzleUNUserNotif class], UNUserNotificationCenterClass);

[OneSignalHelper registerAsUNNotificationCenterDelegate];
#endif
Expand Down
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignal/OneSignalHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

// - Notification Opened
+ (NSDictionary*)getPushTitleBody:(NSDictionary*)messageDict;
+ (NSArray*)getActionButtons;
+ (NSArray*)getActionButtons:(NSDictionary*)messageDict;
+ (void)lastMessageReceived:(NSDictionary*)message;
+ (void)notificationBlocks:(OSHandleNotificationReceivedBlock)receivedBlock :(OSHandleNotificationActionBlock)actionBlock;
+ (void)handleNotificationReceived:(OSNotificationDisplayType)displayType;
Expand Down
113 changes: 67 additions & 46 deletions iOS_SDK/OneSignal/OneSignalHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -306,44 +306,82 @@ + (NSString*)md5:(NSString *)text {
return NULL;
}

+ (NSArray*)getActionButtons {
+ (NSArray*)getActionButtons:(NSDictionary*)messageDict {
if (messageDict[@"os_data"] && [messageDict[@"os_data"] isKindOfClass:[NSDictionary class]])
return messageDict[@"os_data"][@"buttons"][@"o"];

if(!lastMessageReceived) return NULL;

if(lastMessageReceived[@"os_data"] && [lastMessageReceived[@"os_data"] isKindOfClass:[NSDictionary class]]) {
return lastMessageReceived[@"os_data"][@"buttons"][@"o"];
}

return lastMessageReceived[@"o"];
return messageDict[@"o"];
}

+ (NSDictionary*)getPushTitleBody:(NSDictionary*)messageDict {

NSString *title = messageDict[@"m"][@"title"];
NSString *title;
if ([messageDict[@"aps"][@"alert"] isKindOfClass:[NSDictionary class]])
title = messageDict[@"aps"][@"alert"][@"title"];
else
title = messageDict[@"aps"][@"alert"];

if (!title) {
if ([messageDict[@"aps"][@"alert"] isKindOfClass:[NSDictionary class]])
title = messageDict[@"aps"][@"alert"][@"title"];
else
title = messageDict[@"aps"][@"alert"];
if ([messageDict[@"m"] isKindOfClass:[NSDictionary class]])
title = messageDict[@"m"][@"title"];
}

if (!title) {
if ([messageDict[@"os_data"][@"buttons"][@"m"] isKindOfClass:[NSDictionary class]])
title = messageDict[@"os_data"][@"buttons"][@"m"][@"title"];
}

if (!title)
title = messageDict[@"os_data"][@"buttons"][@"m"][@"title"];
if (!title)
title = [[[NSBundle mainBundle] infoDictionary] objectForKey:(id)kCFBundleNameKey];
if (!title)
title = @"";


NSString *body = messageDict[@"m"][@"body"];
if (!body && [messageDict[@"aps"][@"alert"] isKindOfClass:[NSDictionary class]])
NSString *subtitle;
if ([messageDict[@"aps"][@"alert"] isKindOfClass:[NSDictionary class]])
subtitle = messageDict[@"aps"][@"alert"][@"subtitle"];
else
subtitle = messageDict[@"aps"][@"alert"];

if (!subtitle) {
if ([messageDict[@"m"] isKindOfClass:[NSDictionary class]])
subtitle = messageDict[@"m"][@"subtitle"];
}

if (!subtitle) {
if ([messageDict[@"os_data"][@"buttons"][@"m"] isKindOfClass:[NSDictionary class]])
subtitle = messageDict[@"os_data"][@"buttons"][@"m"][@"subtitle"];
}

if (!subtitle)
subtitle = @"";



NSString *body;
if ([messageDict[@"aps"][@"alert"] isKindOfClass:[NSDictionary class]])
body = messageDict[@"aps"][@"alert"][@"body"];
if (!body)
body = messageDict[@"os_data"][@"buttons"][@"m"][@"body"];
else
body = messageDict[@"aps"][@"alert"];

if (!body) {
if ([messageDict[@"m"] isKindOfClass:[NSDictionary class]])
body = messageDict[@"m"][@"body"];
else
body = messageDict[@"m"];
}

if (!body) {
if ([messageDict[@"os_data"][@"buttons"][@"m"] isKindOfClass:[NSDictionary class]])
body = messageDict[@"os_data"][@"buttons"][@"m"][@"body"];
else
body = messageDict[@"os_data"][@"buttons"][@"m"];
}

if (!body)
body = @"";

return @{@"title" : title, @"body": body};
return @{@"title" : title, @"subtitle": subtitle, @"body": body};
}

// Prevent the OSNotification blocks from firing if we receive a Non-OneSignal remote push
Expand Down Expand Up @@ -408,7 +446,7 @@ + (UILocalNotification*)createUILocalNotification:(NSDictionary*)data {

Class UIMutableUserNotificationActionClass = NSClassFromString(@"UIMutableUserNotificationAction");
NSMutableArray* actionArray = [[NSMutableArray alloc] init];
for (NSDictionary* button in data[@"o"]) {
for (NSDictionary* button in [OneSignalHelper getActionButtons:data]) {
id action = [[UIMutableUserNotificationActionClass alloc] init];
[action setTitle:button[@"n"]];
[action setIdentifier:button[@"i"] ? button[@"i"] : [action title]];
Expand All @@ -428,9 +466,10 @@ + (UILocalNotification*)createUILocalNotification:(NSDictionary*)data {
NSUInteger notificationTypes = NOTIFICATION_TYPE_ALL;

NSSet* currentCategories = [[[UIApplication sharedApplication] currentUserNotificationSettings] categories];
if(currentCategories)
if (currentCategories)
currentCategories = [currentCategories setByAddingObject:category];
else currentCategories = [NSSet setWithObject:category];
else
currentCategories = [NSSet setWithObject:category];

[[UIApplication sharedApplication] registerUserNotificationSettings:[uiUserNotificationSettings settingsForTypes:notificationTypes categories:currentCategories]];
notification.category = [category identifier];
Expand Down Expand Up @@ -509,7 +548,7 @@ + (id)prepareUNNotificationRequest:(NSDictionary *)data :(NSDictionary *)userInf
return NULL;

NSMutableArray * actionArray = [[NSMutableArray alloc] init];
for(NSDictionary* button in data[@"o"]) {
for(NSDictionary* button in [OneSignalHelper getActionButtons:data]) {
NSString* title = button[@"n"] != NULL ? button[@"n"] : @"";
NSString* buttonID = button[@"i"] != NULL ? button[@"i"] : title;
id action = [NSClassFromString(@"UNNotificationAction") actionWithIdentifier:buttonID title:title options:UNNotificationActionOptionForeground];
Expand All @@ -528,28 +567,10 @@ + (id)prepareUNNotificationRequest:(NSDictionary *)data :(NSDictionary *)userInf
id content = [[NSClassFromString(@"UNMutableNotificationContent") alloc] init];
[content setValue:@"__dynamic__" forKey:@"categoryIdentifier"];

if (data[@"m"]) {
if([data[@"m"] isKindOfClass:[NSDictionary class]]) {
if(data[@"m"][@"title"])
[content setValue:data[@"m"][@"title"] forKey:@"title"];
if(data[@"m"][@"body"])
[content setValue:data[@"m"][@"body"] forKey:@"body"];
if(data[@"m"][@"subtitle"])
[content setValue:data[@"m"][@"subtitle"] forKey:@"subtitle"];
}
else
[content setValue:data[@"m"] forKey:@"body"];
}

else if(data[@"aps"][@"alert"]) {
if ([data[@"aps"][@"alert"] isKindOfClass:[NSDictionary class]]) {
[content setValue:data[@"aps"][@"alert"][@"title"] forKey:@"title"];
[content setValue:data[@"aps"][@"alert"][@"body"] forKey:@"body"];
[content setValue:data[@"aps"][@"alert"][@"subtitle"] forKey:@"subtitle"];
}
else
[content setValue:data[@"aps"][@"alert"] forKey:@"body"];
}
NSDictionary* alertDict = [OneSignalHelper getPushTitleBody:data];
[content setValue:alertDict[@"title"] forKey:@"title"];
[content setValue:alertDict[@"subtitle"] forKey:@"subtitle"];
[content setValue:alertDict[@"body"] forKey:@"body"];

[content setValue:userInfo forKey:@"userInfo"];

Expand Down
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignal/UNUserNotificationCenter+OneSignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#import "OneSignal.h"

#if XC8_AVAILABLE
@interface sizzleUNUserNotif : NSObject
@interface swizzleUNUserNotif : NSObject
@end
#endif

Expand Down
Loading