@@ -56,6 +56,12 @@ it will add the observers (ie. subscription)
56
56
@property (strong , nonatomic ) NSMutableDictionary * notificationCompletionCache;
57
57
@property (strong , nonatomic ) NSMutableDictionary * receivedNotificationCache;
58
58
59
+ @property (atomic ) BOOL hasSetOnWillDisplayInAppMessageHandler;
60
+ @property (atomic ) BOOL hasSetOnDidDisplayInAppMessageHandler;
61
+ @property (atomic ) BOOL hasSetOnWillDismissInAppMessageHandler;
62
+ @property (atomic ) BOOL hasSetOnDidDismissInAppMessageHandler;
63
+
64
+ @property (strong , nonatomic ) OSInAppMessage *inAppMessage;
59
65
@end
60
66
61
67
@implementation OneSignalPlugin
@@ -70,6 +76,10 @@ + (instancetype)sharedInstance {
70
76
sharedInstance.notificationCompletionCache = [NSMutableDictionary new ];;
71
77
sharedInstance.hasSetInAppMessageClickedHandler = false ;
72
78
sharedInstance.hasSetNotificationWillShowInForegroundHandler = false ;
79
+ sharedInstance.hasSetOnWillDisplayInAppMessageHandler = false ;
80
+ sharedInstance.hasSetOnDidDisplayInAppMessageHandler = false ;
81
+ sharedInstance.hasSetOnWillDismissInAppMessageHandler = false ;
82
+ sharedInstance.hasSetOnDidDismissInAppMessageHandler = false ;
73
83
});
74
84
return sharedInstance;
75
85
}
@@ -152,6 +162,14 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
152
162
[self initNotificationWillShowInForegroundHandlerParams ];
153
163
else if ([@" OneSignal#completeNotification" isEqualToString: call.method])
154
164
[self completeNotification: call withResult: result];
165
+ else if ([@" OneSignal#onWillDisplayInAppMessageHandlerParams" isEqualToString: call.method])
166
+ [self onWillDisplayInAppMessageHandlerParams ];
167
+ else if ([@" OneSignal#onDidDisplayInAppMessageHandlerParams" isEqualToString: call.method])
168
+ [self onDidDisplayInAppMessageHandlerParams ];
169
+ else if ([@" OneSignal#onWillDismissInAppMessageHandlerParams" isEqualToString: call.method])
170
+ [self onWillDismissInAppMessageHandlerParams ];
171
+ else if ([@" OneSignal#onDidDismissInAppMessageHandlerParams" isEqualToString: call.method])
172
+ [self onDidDismissInAppMessageHandlerParams ];
155
173
else
156
174
result (FlutterMethodNotImplemented);
157
175
}
@@ -160,6 +178,8 @@ - (void)setAppId:(FlutterMethodCall *)call withResult:(FlutterResult)result {
160
178
[OneSignal setInAppMessageClickHandler: ^(OSInAppMessageAction *action) {
161
179
[self handleInAppMessageClicked: action];
162
180
}];
181
+
182
+ [OneSignal setInAppMessageLifecycleHandler: self ];
163
183
164
184
[OneSignal setAppId: call.arguments[@" appId" ]];
165
185
@@ -399,6 +419,60 @@ - (void)handleInAppMessageClicked:(OSInAppMessageAction *)action {
399
419
[self .channel invokeMethod: @" OneSignal#handleClickedInAppMessage" arguments: action.toJson];
400
420
}
401
421
422
+ #pragma mark In App Message lifecycle Handler
423
+ - (void )onWillDisplayInAppMessageHandlerParams {
424
+ self.hasSetOnWillDisplayInAppMessageHandler = YES ;
425
+
426
+ if (self.inAppMessage ) {
427
+ [self onWillDisplayInAppMessage: self .inAppMessage];
428
+ self.inAppMessage = nil ;
429
+ }
430
+ }
431
+
432
+ - (void )onDidDisplayInAppMessageHandlerParams {
433
+ self.hasSetOnDidDisplayInAppMessageHandler = YES ;
434
+
435
+ if (self.inAppMessage ) {
436
+ [self onDidDisplayInAppMessage: self .inAppMessage];
437
+ self.inAppMessage = nil ;
438
+ }
439
+ }
440
+
441
+ - (void )onWillDismissInAppMessageHandlerParams {
442
+ self.hasSetOnWillDismissInAppMessageHandler = YES ;
443
+
444
+ if (self.inAppMessage ) {
445
+ [self onWillDismissInAppMessage: self .inAppMessage];
446
+ self.inAppMessage = nil ;
447
+ }
448
+ }
449
+
450
+ - (void )onDidDismissInAppMessageHandlerParams {
451
+ self.hasSetOnDidDismissInAppMessageHandler = YES ;
452
+
453
+ if (self.inAppMessage ) {
454
+ [self onDidDismissInAppMessage: self .inAppMessage];
455
+ self.inAppMessage = nil ;
456
+ }
457
+ }
458
+
459
+ #pragma mark OSInAppMessageLifeCycleHandler
460
+ - (void )onWillDisplayInAppMessage : (OSInAppMessage *) result {
461
+ [self .channel invokeMethod: @" OneSignal#onWillDisplayInAppMessage" arguments: result.toJson];
462
+ }
463
+
464
+ - (void )onDidDisplayInAppMessage : (OSInAppMessage *) result {
465
+ [self .channel invokeMethod: @" OneSignal#onDidDisplayInAppMessage" arguments: result.toJson];
466
+ }
467
+
468
+ - (void )onWillDismissInAppMessage : (OSInAppMessage *) result {
469
+ [self .channel invokeMethod: @" OneSignal#onWillDismissInAppMessage" arguments: result.toJson];
470
+ }
471
+
472
+ - (void )onDidDismissInAppMessage : (OSInAppMessage *) result {
473
+ [self .channel invokeMethod: @" OneSignal#onDidDismissInAppMessage" arguments: result.toJson];
474
+ }
475
+
402
476
#pragma mark OSSubscriptionObserver
403
477
- (void )onOSSubscriptionChanged : (OSSubscriptionStateChanges *)stateChanges {
404
478
[self .channel invokeMethod: @" OneSignal#subscriptionChanged" arguments: stateChanges.toDictionary];
0 commit comments