1010#import " PushPlugin.h"
1111#import < objc/runtime.h>
1212
13+ static char clobberedDelegateKey;
1314static char launchNotificationKey;
1415static char coldstartKey;
1516NSString *const pushPluginApplicationDidBecomeActiveNotification = @" pushPluginApplicationDidBecomeActiveNotification" ;
1617
17-
1818@implementation AppDelegate (notification)
1919
2020- (id ) getCommandInstance : (NSString *)className
@@ -56,6 +56,7 @@ + (void)load
5656- (AppDelegate *)pushPluginSwizzledInit
5757{
5858 UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter ];
59+ self.clobberedDelegate = center.delegate ;
5960 center.delegate = self;
6061
6162 [[NSNotificationCenter defaultCenter ]addObserver:self
@@ -190,6 +191,14 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
190191 willPresentNotification : (UNNotification *)notification
191192 withCompletionHandler : (void (^)(UNNotificationPresentationOptions options))completionHandler
192193{
194+ if (![notification.request.trigger isKindOfClass: [UNPushNotificationTrigger class ]])
195+ {
196+ [self .clobberedDelegate userNotificationCenter: center
197+ willPresentNotification: notification
198+ withCompletionHandler: completionHandler];
199+ return ;
200+ }
201+
193202 NSLog ( @" NotificationCenter Handle push from foreground" );
194203 // custom code to handle push while app is in the foreground
195204 PushPlugin *pushHandler = [self getCommandInstance: @" PushNotification" ];
@@ -204,6 +213,14 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
204213didReceiveNotificationResponse : (UNNotificationResponse *)response
205214 withCompletionHandler : (void (^)(void ))completionHandler
206215{
216+ if (![response.notification.request.trigger isKindOfClass: [UNPushNotificationTrigger class ]])
217+ {
218+ [self .clobberedDelegate userNotificationCenter: center
219+ didReceiveNotificationResponse: response
220+ withCompletionHandler: completionHandler];
221+ return ;
222+ }
223+
207224 NSLog (@" Push Plugin didReceiveNotificationResponse: actionIdentifier %@ , notification: %@ " , response.actionIdentifier ,
208225 response.notification .request .content .userInfo );
209226 NSMutableDictionary *userInfo = [response.notification.request.content.userInfo mutableCopy ];
@@ -260,6 +277,16 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
260277
261278// The accessors use an Associative Reference since you can't define a iVar in a category
262279// http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/Chapters/ocAssociativeReferences.html
280+ - (id <UNUserNotificationCenterDelegate >)clobberedDelegate
281+ {
282+ return objc_getAssociatedObject (self, &clobberedDelegateKey);
283+ }
284+
285+ - (void )setClobberedDelegate : (id <UNUserNotificationCenterDelegate >)clobberedDelegate
286+ {
287+ objc_setAssociatedObject (self, &clobberedDelegateKey, clobberedDelegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC );
288+ }
289+
263290- (NSMutableArray *)launchNotification
264291{
265292 return objc_getAssociatedObject (self, &launchNotificationKey);
0 commit comments