@@ -40,7 +40,7 @@ + (void) handleDidFailRegisterForRemoteNotification:(NSError*)error;
4040+ (void ) updateNotificationTypes : (int )notificationTypes ;
4141+ (NSString *) app_id ;
4242+ (void ) notificationOpened : (NSDictionary *)messageDict isActive : (BOOL )isActive ;
43- + (void ) remoteSilentNotification : (UIApplication*)application UserInfo : (NSDictionary *)userInfo completionHandler : (void (^)(UIBackgroundFetchResult))completionHandler ;
43+ + (BOOL ) remoteSilentNotification : (UIApplication*)application UserInfo : (NSDictionary *)userInfo completionHandler : (void (^)(UIBackgroundFetchResult))completionHandler ;
4444+ (void ) processLocalActionBasedNotification : (UILocalNotification*) notification identifier : (NSString *)identifier ;
4545+ (void ) onesignal_Log : (ONE_S_LOG_LEVEL)logLevel message : (NSString *) message ;
4646@end
@@ -180,29 +180,36 @@ - (void)oneSignalReceivedRemoteNotification:(UIApplication*)application userInfo
180180 [self oneSignalReceivedRemoteNotification: application userInfo: userInfo];
181181}
182182
183- // User Tap on Notification while app was in background - OR - Notification received (silent or not, foreground or background) on iOS 7+
183+ // Fires when a notication is opened or recieved while the app is in focus.
184+ // - Also fires when the app is in the background and a notificaiton with content-available=1 is received.
185+ // NOTE: completionHandler must only be called once!
186+ // iOS 10 - This crashes the app if it is called twice! Crash will happen when the app is resumed.
187+ // iOS 9 - Does not have this issue.
184188- (void ) oneSignalRemoteSilentNotification : (UIApplication*)application UserInfo : (NSDictionary *)userInfo fetchCompletionHandler : (void (^)(UIBackgroundFetchResult)) completionHandler {
185189 [OneSignal onesignal_Log: ONE_S_LL_VERBOSE message: @" oneSignalRemoteSilentNotification:UserInfo:fetchCompletionHandler:" ];
186190
191+ BOOL callExistingSelector = [self respondsToSelector: @selector (oneSignalRemoteSilentNotification:UserInfo:fetchCompletionHandler: )];
192+ BOOL startedBackgroundJob = false ;
193+
187194 if ([OneSignal app_id ]) {
188- // Call notificationAction if app is active -> not a silent notification but rather user tap on notification
189- // Unless iOS 10+ then call remoteSilentNotification instead.
190195 if ([UIApplication sharedApplication ].applicationState == UIApplicationStateActive && userInfo[@" aps" ][@" alert" ])
191196 [OneSignal notificationOpened: userInfo isActive: YES ];
192197 else
193- [OneSignal remoteSilentNotification: application UserInfo: userInfo completionHandler: completionHandler];
198+ startedBackgroundJob = [OneSignal remoteSilentNotification: application UserInfo: userInfo completionHandler: callExistingSelector ? nil : completionHandler];
194199 }
195200
196- if ([ self respondsToSelector: @selector ( oneSignalRemoteSilentNotification:UserInfo:fetchCompletionHandler: )] ) {
201+ if (callExistingSelector ) {
197202 [self oneSignalRemoteSilentNotification: application UserInfo: userInfo fetchCompletionHandler: completionHandler];
198203 return ;
199204 }
200205
201206 // Make sure not a cold start from tap on notification (OS doesn't call didReceiveRemoteNotification)
202- if ([self respondsToSelector: @selector (oneSignalReceivedRemoteNotification:userInfo: )] && ![[OneSignal valueForKey: @" coldStartFromTapOnNotification" ] boolValue ])
207+ if ([self respondsToSelector: @selector (oneSignalReceivedRemoteNotification:userInfo: )]
208+ && ![[OneSignal valueForKey: @" coldStartFromTapOnNotification" ] boolValue ])
203209 [self oneSignalReceivedRemoteNotification: application userInfo: userInfo];
204210
205- completionHandler (UIBackgroundFetchResultNewData);
211+ if (!startedBackgroundJob)
212+ completionHandler (UIBackgroundFetchResultNewData);
206213}
207214
208215- (void ) oneSignalLocalNotificationOpened : (UIApplication*)application handleActionWithIdentifier : (NSString *)identifier forLocalNotification : (UILocalNotification*)notification completionHandler : (void (^)()) completionHandler {
0 commit comments