@@ -44,6 +44,8 @@ it will add the observers (ie. subscription)
44
44
*/
45
45
@property (atomic ) BOOL waitingForUserConsent;
46
46
47
+ @property (atomic ) BOOL hasSetNotificationOpenedHandler;
48
+ @property (atomic ) BOOL hasSetInAppMessageClickedHandler;
47
49
@property (atomic ) BOOL hasSetNotificationWillShowInForegroundHandler;
48
50
49
51
/*
@@ -76,6 +78,9 @@ + (instancetype)sharedInstance {
76
78
sharedInstance.waitingForUserConsent = false ;
77
79
sharedInstance.receivedNotificationCache = [NSMutableDictionary new ];;
78
80
sharedInstance.notificationCompletionCache = [NSMutableDictionary new ];;
81
+ sharedInstance.hasSetNotificationOpenedHandler = false ;
82
+ sharedInstance.hasSetInAppMessageClickedHandler = false ;
83
+ sharedInstance.hasSetNotificationWillShowInForegroundHandler = false ;
79
84
});
80
85
return sharedInstance;
81
86
}
@@ -104,12 +109,12 @@ - (void)addObservers {
104
109
[OneSignal addSubscriptionObserver: self ];
105
110
[OneSignal addPermissionObserver: self ];
106
111
[OneSignal addEmailSubscriptionObserver: self ];
107
- [OneSignal setNotificationOpenedHandler: ^(OSNotificationOpenedResult * _Nonnull result) {
108
- [OneSignalPlugin.sharedInstance handleNotificationOpened: result];
109
- }];
110
112
[OneSignal setNotificationWillShowInForegroundHandler: ^(OSNotification *notification, OSNotificationDisplayResponse completion) {
111
113
[OneSignalPlugin.sharedInstance handleNotificationWillShowInForeground: notification completion: completion];
112
114
}];
115
+ [OneSignal setNotificationOpenedHandler: ^(OSNotificationOpenedResult * _Nonnull result) {
116
+ [OneSignalPlugin.sharedInstance handleNotificationOpened: result];
117
+ }];
113
118
}
114
119
115
120
- (void )handleMethodCall : (FlutterMethodCall*)call result : (FlutterResult)result {
@@ -300,13 +305,17 @@ - (void)removeExternalUserId:(FlutterMethodCall *)call withResult:(FlutterResult
300
305
}
301
306
302
307
- (void )initNotificationOpenedHandlerParams {
308
+ _hasSetNotificationOpenedHandler = true ;
309
+
303
310
if (self.coldStartOpenResult ) {
304
311
[self handleNotificationOpened: self .coldStartOpenResult];
305
312
self.coldStartOpenResult = nil ;
306
313
}
307
314
}
308
315
309
316
- (void )initInAppMessageClickedHandlerParams {
317
+ _hasSetInAppMessageClickedHandler = true ;
318
+
310
319
if (self.inAppMessageClickedResult ) {
311
320
[self handleInAppMessageClicked: self .inAppMessageClickedResult];
312
321
self.inAppMessageClickedResult = nil ;
@@ -319,6 +328,11 @@ - (void)initNotificationWillShowInForegroundHandlerParams {
319
328
320
329
#pragma mark Opened Notification Handlers
321
330
- (void )handleNotificationOpened : (OSNotificationOpenedResult *)result {
331
+ if (!self.hasSetNotificationOpenedHandler ) {
332
+ _coldStartOpenResult = result;
333
+ return ;
334
+ }
335
+
322
336
[self .channel invokeMethod: @" OneSignal#handleOpenedNotification" arguments: result.toJson];
323
337
}
324
338
@@ -358,6 +372,11 @@ - (void)completeNotification:(FlutterMethodCall *)call withResult:(FlutterResult
358
372
359
373
#pragma mark In App Message Click Handler
360
374
- (void )handleInAppMessageClicked : (OSInAppMessageAction *)action {
375
+ if (!self.hasSetInAppMessageClickedHandler ) {
376
+ _inAppMessageClickedResult = action;
377
+ return ;
378
+ }
379
+
361
380
[self .channel invokeMethod: @" OneSignal#handleClickedInAppMessage" arguments: action.toJson];
362
381
}
363
382
0 commit comments