From 381c5ac8486e54ea1bffd39d73515bab9a977cbc Mon Sep 17 00:00:00 2001 From: Kasten Date: Thu, 10 Nov 2016 00:07:52 -0800 Subject: [PATCH 1/2] Calling all 6 Legacy notifiation selectors for compatability --- iOS_SDK/OneSignal/OneSignal.m | 2 +- .../UNUserNotificationCenter+OneSignal.h | 2 +- .../UNUserNotificationCenter+OneSignal.m | 156 +++++++++++++----- 3 files changed, 113 insertions(+), 47 deletions(-) diff --git a/iOS_SDK/OneSignal/OneSignal.m b/iOS_SDK/OneSignal/OneSignal.m index 22662b535..cbe3e0373 100755 --- a/iOS_SDK/OneSignal/OneSignal.m +++ b/iOS_SDK/OneSignal/OneSignal.m @@ -1303,7 +1303,7 @@ + (void)load { return; injectToProperClass(@selector(setOneSignalUNDelegate:), - @selector(setDelegate:), @[], [sizzleUNUserNotif class], UNUserNotificationCenterClass); + @selector(setDelegate:), @[], [swizzleUNUserNotif class], UNUserNotificationCenterClass); [OneSignalHelper registerAsUNNotificationCenterDelegate]; #endif diff --git a/iOS_SDK/OneSignal/UNUserNotificationCenter+OneSignal.h b/iOS_SDK/OneSignal/UNUserNotificationCenter+OneSignal.h index 941ce97b7..3d042bd2d 100644 --- a/iOS_SDK/OneSignal/UNUserNotificationCenter+OneSignal.h +++ b/iOS_SDK/OneSignal/UNUserNotificationCenter+OneSignal.h @@ -31,7 +31,7 @@ #import "OneSignal.h" #if XC8_AVAILABLE -@interface sizzleUNUserNotif : NSObject +@interface swizzleUNUserNotif : NSObject @end #endif diff --git a/iOS_SDK/OneSignal/UNUserNotificationCenter+OneSignal.m b/iOS_SDK/OneSignal/UNUserNotificationCenter+OneSignal.m index 28e0f688f..8fc55d435 100644 --- a/iOS_SDK/OneSignal/UNUserNotificationCenter+OneSignal.m +++ b/iOS_SDK/OneSignal/UNUserNotificationCenter+OneSignal.m @@ -53,7 +53,7 @@ + (void)notificationOpened:(NSDictionary*)messageDict isActive:(BOOL)isActive; // - The presents of this selector tells iOS to no longer fire `application:didReceiveRemoteNotification:fetchCompletionHandler:`. // We call this to maintain existing behavior. -@implementation sizzleUNUserNotif +@implementation swizzleUNUserNotif static Class delegateUNClass = nil; @@ -65,21 +65,21 @@ @implementation sizzleUNUserNotif // - Selector will be called once if developer does not set a UNUserNotificationCenter delegate. // - Selector will be called a 2nd time if the developer does set one. - (void) setOneSignalUNDelegate:(id)delegate { - [OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"sizzleUNUserNotif setOneSignalUNDelegate Fired!"]; + [OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"swizzleUNUserNotif setOneSignalUNDelegate Fired!"]; delegateUNClass = getClassWithProtocolInHierarchy([delegate class], @protocol(UNUserNotificationCenterDelegate)); delegateUNSubclasses = ClassGetSubclasses(delegateUNClass); injectToProperClass(@selector(onesignalUserNotificationCenter:willPresentNotification:withCompletionHandler:), - @selector(userNotificationCenter:willPresentNotification:withCompletionHandler:), delegateUNSubclasses, [sizzleUNUserNotif class], delegateUNClass); + @selector(userNotificationCenter:willPresentNotification:withCompletionHandler:), delegateUNSubclasses, [swizzleUNUserNotif class], delegateUNClass); injectToProperClass(@selector(onesignalUserNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:), - @selector(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:), delegateUNSubclasses, [sizzleUNUserNotif class], delegateUNClass); + @selector(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:), delegateUNSubclasses, [swizzleUNUserNotif class], delegateUNClass); [self setOneSignalUNDelegate:delegate]; } -// Apples docs - Called when a notification is delivered to a foreground app. +// Apple's docs - Called when a notification is delivered to a foreground app. - (void)onesignalUserNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { @@ -121,30 +121,30 @@ - (void)onesignalUserNotificationCenter:(UNUserNotificationCenter *)center } // Apple's docs - Called to let your app know which action was selected by the user for a given notification. -- (void)onesignalUserNotificationCenter:(id)center didReceiveNotificationResponse:(id)response withCompletionHandler:(void(^)())completionHandler { +- (void)onesignalUserNotificationCenter:(UNUserNotificationCenter *)center + didReceiveNotificationResponse:(UNNotificationResponse *)response + withCompletionHandler:(void(^)())completionHandler { [OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"onesignalUserNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: Fired!"]; - NSDictionary* usrInfo = [[[[response performSelector:@selector(notification)] valueForKey:@"request"] valueForKey:@"content"] valueForKey:@"userInfo"]; - if (!usrInfo || [usrInfo count] == 0) { - [sizzleUNUserNotif tunnelToDelegate:center response:response handler:completionHandler]; - return; - } + BOOL isActive = [UIApplication sharedApplication].applicationState == UIApplicationStateActive && + [[[NSUserDefaults standardUserDefaults] objectForKey:@"ONESIGNAL_ALERT_OPTION"] intValue] != OSNotificationDisplayTypeNotification; + NSDictionary* remoteUserInfo = response.notification.request.content.userInfo; NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init], *customDict = [[NSMutableDictionary alloc] init], *additionalData = [[NSMutableDictionary alloc] init]; NSMutableArray *optionsDict = [[NSMutableArray alloc] init]; - NSMutableDictionary* buttonsDict = usrInfo[@"os_data"][@"buttons"]; - NSMutableDictionary* custom = usrInfo[@"custom"]; + NSMutableDictionary* buttonsDict = remoteUserInfo[@"os_data"][@"buttons"]; + NSMutableDictionary* custom = remoteUserInfo[@"custom"]; if (buttonsDict) { - [userInfo addEntriesFromDictionary:usrInfo]; + [userInfo addEntriesFromDictionary:remoteUserInfo]; NSArray* o = buttonsDict[@"o"]; if (o) [optionsDict addObjectsFromArray:o]; } else if (custom) { - [userInfo addEntriesFromDictionary:usrInfo]; + [userInfo addEntriesFromDictionary:remoteUserInfo]; [customDict addEntriesFromDictionary:custom]; NSDictionary *a = customDict[@"a"]; NSArray *o = userInfo[@"o"]; @@ -153,13 +153,6 @@ - (void)onesignalUserNotificationCenter:(id)center didReceiveNotificationRespons if (o) [optionsDict addObjectsFromArray:o]; } - else { - BOOL isActive = [UIApplication sharedApplication].applicationState == UIApplicationStateActive && - [[[NSUserDefaults standardUserDefaults] objectForKey:@"ONESIGNAL_ALERT_OPTION"] intValue] != OSNotificationDisplayTypeNotification; - [OneSignal notificationOpened:usrInfo isActive:isActive]; - [sizzleUNUserNotif tunnelToDelegate:center response:response handler:completionHandler]; - return; - } NSMutableArray* buttonArray = [[NSMutableArray alloc] init]; for (NSDictionary* button in optionsDict) { @@ -172,7 +165,7 @@ - (void)onesignalUserNotificationCenter:(id)center didReceiveNotificationRespons additionalData[@"actionSelected"] = [response valueForKey:@"actionIdentifier"]; additionalData[@"actionButtons"] = buttonArray; - NSDictionary* os_data = usrInfo[@"os_data"]; + NSDictionary* os_data = remoteUserInfo[@"os_data"]; if (os_data) { [userInfo addEntriesFromDictionary:os_data]; if (userInfo[@"os_data"][@"buttons"][@"m"]) @@ -182,40 +175,113 @@ - (void)onesignalUserNotificationCenter:(id)center didReceiveNotificationRespons else { customDict[@"a"] = additionalData; userInfo[@"custom"] = customDict; - if(userInfo[@"m"]) - userInfo[@"aps"] = @{ @"alert" : userInfo[@"m"] }; + if (userInfo[@"m"]) + userInfo[@"aps"] = @{ @"alert": userInfo[@"m"] }; } - UIApplication *sharedApp = [UIApplication sharedApplication]; - - BOOL isActive = sharedApp.applicationState == UIApplicationStateActive && - [[[NSUserDefaults standardUserDefaults] objectForKey:@"ONESIGNAL_ALERT_OPTION"] intValue] != OSNotificationDisplayTypeNotification; - if ([OneSignal app_id]) [OneSignal notificationOpened:userInfo isActive:isActive]; - [sizzleUNUserNotif tunnelToDelegate:center response:response handler:completionHandler]; + + // For depercated OSUserNotificationCenterDelegate + [swizzleUNUserNotif tunnelToDelegate:center response:response handler:completionHandler]; // Call orginal selector if one was set. if ([self respondsToSelector:@selector(onesignalUserNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]) [self onesignalUserNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler]; - else if ([sharedApp.delegate respondsToSelector:@selector(application:didReceiveRemoteNotification:fetchCompletionHandler:)]) { - // Call depercated pre-iOS 10 selector if one as set on the AppDelegate. - // NOTE: Should always be true as our AppDelegate swizzling should be there unless something else unsizzled it. - [sharedApp.delegate application:sharedApp didReceiveRemoteNotification:usrInfo fetchCompletionHandler:^(UIBackgroundFetchResult result) { - // Call iOS 10's compleationHandler from iOS 9's completion handler. - completionHandler(); - }]; - } + else + [swizzleUNUserNotif callLegacyAppDeletegateSelector:response withCompletionHandler:completionHandler]; } // Depercated - [OneSignal notificationCenterDelegate] - Now handled by swizzling. -// Just need to keep the `handler();` call -+ (void)tunnelToDelegate:(id)center response:(id)response handler:(void (^)())handler { - - if ([[OneSignal notificationCenterDelegate] respondsToSelector:@selector(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]) ++ (BOOL)tunnelToDelegate:(id)center response:(id)response handler:(void (^)())handler { + if ([[OneSignal notificationCenterDelegate] respondsToSelector:@selector(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]) { [[OneSignal notificationCenterDelegate] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:handler]; - else - handler(); + return true; + } + + return false; +} + +// Calls depercated pre-iOS 10 selector if one is set on the AppDelegate. +// - application:didReceiveLocalNotification: +// - application:didReceiveRemoteNotification:fetchCompletionHandler: +// - application:handleActionWithIdentifier:forLocalNotification:withResponseInfo:completionHandler: +// - application:handleActionWithIdentifier:forRemoteNotification:withResponseInfo:completionHandler: +// - application:handleActionWithIdentifier:forLocalNotification:completionHandler: +// - application:handleActionWithIdentifier:forRemoteNotification:completionHandler: ++ (void)callLegacyAppDeletegateSelector:(UNNotificationResponse *)response + withCompletionHandler:(void(^)())completionHandler { + UIApplication *sharedApp = [UIApplication sharedApplication]; + + BOOL isTextReply = [response isKindOfClass:NSClassFromString(@"UNTextInputNotificationResponse")]; + BOOL isLegacyLocalNotif = [response.notification.request.trigger isKindOfClass:NSClassFromString(@"UNLegacyNotificationTrigger")]; + BOOL isCustomAction = ![@"com.apple.UNNotificationDefaultActionIdentifier" isEqualToString:response.actionIdentifier]; + // BOOL isRemote = [response.notification.request.trigger isKindOfClass:NSClassFromString(@"UNPushNotificationTrigger")]; + + if (isLegacyLocalNotif) { + UILocalNotification *localNotif = [NSClassFromString(@"UIConcreteLocalNotification") alloc]; + localNotif.alertBody = response.notification.request.content.body; + localNotif.alertTitle = response.notification.request.content.title; + localNotif.applicationIconBadgeNumber = [response.notification.request.content.badge integerValue]; + NSString* soundName = [response.notification.request.content.sound valueForKey:@"_toneFileName"]; + if (!soundName) + soundName = @"UILocalNotificationDefaultSoundName"; + localNotif.soundName = soundName; + localNotif.alertLaunchImage = response.notification.request.content.launchImageName; + localNotif.userInfo = response.notification.request.content.userInfo; + localNotif.category = response.notification.request.content.categoryIdentifier; + localNotif.hasAction = true; // Defaults to true, UNLocalNotification doesn't seem to have a flag for this. + localNotif.fireDate = response.notification.date; + localNotif.timeZone = [response.notification.request.trigger valueForKey:@"_timeZone"]; + localNotif.repeatInterval = [response.notification.request.trigger valueForKey:@"_repeatInterval"]; + localNotif.repeatCalendar = [response.notification.request.trigger valueForKey:@"_repeatCalendar"]; + // localNotif.region = + // localNotif.regionTriggersOnce = + + if (isTextReply && + [sharedApp.delegate respondsToSelector:@selector(application:handleActionWithIdentifier:forLocalNotification:withResponseInfo:completionHandler:)]) { + NSDictionary* dict = @{UIUserNotificationActionResponseTypedTextKey: [response valueForKey:@"userText"]}; + [sharedApp.delegate application:sharedApp handleActionWithIdentifier:response.actionIdentifier forLocalNotification:localNotif withResponseInfo:dict completionHandler:^() { + completionHandler(); + }]; + } + else if (isCustomAction && + [sharedApp.delegate respondsToSelector:@selector(application:handleActionWithIdentifier:forLocalNotification:completionHandler:)]) + [sharedApp.delegate application:sharedApp handleActionWithIdentifier:response.actionIdentifier forLocalNotification:localNotif completionHandler:^() { + completionHandler(); + }]; + else if ([sharedApp.delegate respondsToSelector:@selector(application:didReceiveLocalNotification:)]) { + [sharedApp.delegate application:sharedApp didReceiveLocalNotification:localNotif]; + completionHandler(); + } + else + completionHandler(); + } + else { + NSDictionary* remoteUserInfo = response.notification.request.content.userInfo; + + if (isTextReply && + [sharedApp.delegate respondsToSelector:@selector(application:handleActionWithIdentifier:forRemoteNotification:withResponseInfo:completionHandler:)]) { + NSDictionary* responseInfo = @{UIUserNotificationActionResponseTypedTextKey: [response valueForKey:@"userText"]}; + [sharedApp.delegate application:sharedApp handleActionWithIdentifier:response.actionIdentifier forRemoteNotification:remoteUserInfo withResponseInfo:responseInfo completionHandler:^() { + completionHandler(); + }]; + } + else if (isCustomAction && + [sharedApp.delegate respondsToSelector:@selector(application:handleActionWithIdentifier:forRemoteNotification:completionHandler:)]) + [sharedApp.delegate application:sharedApp handleActionWithIdentifier:response.actionIdentifier forRemoteNotification:remoteUserInfo completionHandler:^() { + completionHandler(); + }]; + else if ([sharedApp.delegate respondsToSelector:@selector(application:didReceiveRemoteNotification:fetchCompletionHandler:)]) { + // NOTE: Should always be true as our AppDelegate swizzling should be there unless something else unswizzled it. + [sharedApp.delegate application:sharedApp didReceiveRemoteNotification:remoteUserInfo fetchCompletionHandler:^(UIBackgroundFetchResult result) { + // Call iOS 10's compleationHandler from iOS 9's completion handler. + completionHandler(); + }]; + } + else + completionHandler(); + } } @end From 391849d95325749bda9d4637553f33f7d029842a Mon Sep 17 00:00:00 2001 From: Kasten Date: Thu, 10 Nov 2016 21:29:03 -0800 Subject: [PATCH 2/2] Fixed os_data format for buttons and ios_attachments --- iOS_SDK/OneSignal/OneSignal.m | 19 +-- iOS_SDK/OneSignal/OneSignalHelper.h | 2 +- iOS_SDK/OneSignal/OneSignalHelper.m | 113 +++++++++++------- .../UNUserNotificationCenter+OneSignal.m | 2 +- 4 files changed, 79 insertions(+), 57 deletions(-) diff --git a/iOS_SDK/OneSignal/OneSignal.m b/iOS_SDK/OneSignal/OneSignal.m index cbe3e0373..708fe8dc6 100755 --- a/iOS_SDK/OneSignal/OneSignal.m +++ b/iOS_SDK/OneSignal/OneSignal.m @@ -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]; @@ -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*); @@ -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 { @@ -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) { diff --git a/iOS_SDK/OneSignal/OneSignalHelper.h b/iOS_SDK/OneSignal/OneSignalHelper.h index 0e52f4ef5..16111d2e1 100644 --- a/iOS_SDK/OneSignal/OneSignalHelper.h +++ b/iOS_SDK/OneSignal/OneSignalHelper.h @@ -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; diff --git a/iOS_SDK/OneSignal/OneSignalHelper.m b/iOS_SDK/OneSignal/OneSignalHelper.m index 1ac8b50af..52107a41b 100644 --- a/iOS_SDK/OneSignal/OneSignalHelper.m +++ b/iOS_SDK/OneSignal/OneSignalHelper.m @@ -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 @@ -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]]; @@ -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]; @@ -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]; @@ -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"]; diff --git a/iOS_SDK/OneSignal/UNUserNotificationCenter+OneSignal.m b/iOS_SDK/OneSignal/UNUserNotificationCenter+OneSignal.m index 8fc55d435..66e8725d4 100644 --- a/iOS_SDK/OneSignal/UNUserNotificationCenter+OneSignal.m +++ b/iOS_SDK/OneSignal/UNUserNotificationCenter+OneSignal.m @@ -233,7 +233,7 @@ + (void)callLegacyAppDeletegateSelector:(UNNotificationResponse *)response localNotif.hasAction = true; // Defaults to true, UNLocalNotification doesn't seem to have a flag for this. localNotif.fireDate = response.notification.date; localNotif.timeZone = [response.notification.request.trigger valueForKey:@"_timeZone"]; - localNotif.repeatInterval = [response.notification.request.trigger valueForKey:@"_repeatInterval"]; + localNotif.repeatInterval = (NSCalendarUnit)[response.notification.request.trigger valueForKey:@"_repeatInterval"]; localNotif.repeatCalendar = [response.notification.request.trigger valueForKey:@"_repeatCalendar"]; // localNotif.region = // localNotif.regionTriggersOnce =