@@ -45,6 +45,13 @@ @interface OneSignal (UN_extra)
4545+ (void )notificationOpened : (NSDictionary *)messageDict isActive : (BOOL )isActive ;
4646@end
4747
48+ // This class hooks into the following iSO 10 UNUserNotificationCenterDelegate selectors:
49+ // - userNotificationCenter:willPresentNotification:withCompletionHandler:
50+ // - Reads kOSSettingsKeyInFocusDisplayOption to respect it's setting.
51+ // - userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:
52+ // - Used to process opening a notifications.
53+ // - The presents of this selector tells iOS to no longer fire `application:didReceiveRemoteNotification:fetchCompletionHandler:`.
54+ // We call this to maintain existing behavior.
4855
4956@implementation sizzleUNUserNotif
5057
@@ -119,7 +126,7 @@ - (void)onesignalUserNotificationCenter:(id)center didReceiveNotificationRespons
119126
120127 NSDictionary * usrInfo = [[[[response performSelector: @selector (notification )] valueForKey: @" request" ] valueForKey: @" content" ] valueForKey: @" userInfo" ];
121128 if (!usrInfo || [usrInfo count ] == 0 ) {
122- [sizzleUNUserNotif tunnelToDelegate: center :response :completionHandler];
129+ [sizzleUNUserNotif tunnelToDelegate: center response : response handler : completionHandler];
123130 return ;
124131 }
125132
@@ -150,7 +157,7 @@ - (void)onesignalUserNotificationCenter:(id)center didReceiveNotificationRespons
150157 BOOL isActive = [UIApplication sharedApplication ].applicationState == UIApplicationStateActive &&
151158 [[[NSUserDefaults standardUserDefaults ] objectForKey: @" ONESIGNAL_ALERT_OPTION" ] intValue ] != OSNotificationDisplayTypeNotification;
152159 [OneSignal notificationOpened: usrInfo isActive: isActive];
153- [sizzleUNUserNotif tunnelToDelegate: center :response :completionHandler];
160+ [sizzleUNUserNotif tunnelToDelegate: center response : response handler : completionHandler];
154161 return ;
155162 }
156163
@@ -179,18 +186,31 @@ - (void)onesignalUserNotificationCenter:(id)center didReceiveNotificationRespons
179186 userInfo[@" aps" ] = @{ @" alert" : userInfo[@" m" ] };
180187 }
181188
182- BOOL isActive = [UIApplication sharedApplication ].applicationState == UIApplicationStateActive &&
183- [[[NSUserDefaults standardUserDefaults ] objectForKey: @" ONESIGNAL_ALERT_OPTION" ] intValue ] != OSNotificationDisplayTypeNotification;
189+ UIApplication *sharedApp = [UIApplication sharedApplication ];
184190
191+ BOOL isActive = sharedApp.applicationState == UIApplicationStateActive &&
192+ [[[NSUserDefaults standardUserDefaults ] objectForKey: @" ONESIGNAL_ALERT_OPTION" ] intValue ] != OSNotificationDisplayTypeNotification;
185193
186- [OneSignal notificationOpened: userInfo isActive: isActive];
187- [sizzleUNUserNotif tunnelToDelegate: center :response :completionHandler];
194+ if ([OneSignal app_id ])
195+ [OneSignal notificationOpened: userInfo isActive: isActive];
196+ [sizzleUNUserNotif tunnelToDelegate: center response: response handler: completionHandler];
188197
198+ // Call orginal selector if one was set.
189199 if ([self respondsToSelector: @selector (onesignalUserNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: )])
190200 [self onesignalUserNotificationCenter: center didReceiveNotificationResponse: response withCompletionHandler: completionHandler];
201+ else if ([sharedApp.delegate respondsToSelector: @selector (application:didReceiveRemoteNotification:fetchCompletionHandler: )]) {
202+ // Call depercated pre-iOS 10 selector if one as set on the AppDelegate.
203+ // NOTE: Should always be true as our AppDelegate swizzling should be there unless something else unsizzled it.
204+ [sharedApp.delegate application: sharedApp didReceiveRemoteNotification: usrInfo fetchCompletionHandler: ^(UIBackgroundFetchResult result) {
205+ // Call iOS 10's compleationHandler from iOS 9's completion handler.
206+ completionHandler ();
207+ }];
208+ }
191209}
192210
193- + (void )tunnelToDelegate : (id )center : (id )response : (void (^)())handler {
211+ // Depercated - [OneSignal notificationCenterDelegate] - Now handled by swizzling.
212+ // Just need to keep the `handler();` call
213+ + (void )tunnelToDelegate : (id )center response : (id )response handler : (void (^)())handler {
194214
195215 if ([[OneSignal notificationCenterDelegate ] respondsToSelector: @selector (userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: )])
196216 [[OneSignal notificationCenterDelegate ] userNotificationCenter: center didReceiveNotificationResponse: response withCompletionHandler: handler];
0 commit comments