Skip to content

Commit 75518ef

Browse files
committed
add back in preview IAMs
* Adding back preview IAM functionality * Use Notification Center to send the preview IAM to the Messaging Controller as it lives in another module * add Post Notification event name to Common Defines
1 parent 5756cfa commit 75518ef

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCommonDefines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152

153153
// APNS params
154154
#define ONESIGNAL_IAM_PREVIEW @"os_in_app_message_preview_id"
155+
#define ONESIGNAL_POST_PREVIEW_IAM @"ONESIGNAL_POST_PREVIEW_IAM"
155156

156157
#define ONESIGNAL_SUPPORTED_ATTACHMENT_TYPES @[@"aiff", @"wav", @"mp3", @"mp4", @"jpg", @"jpeg", @"png", @"gif", @"mpeg", @"mpg", @"avi", @"m4a", @"m4v"]
157158

iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ + (void)notificationReceived:(NSDictionary*)messageDict wasOpened:(BOOL)opened {
562562
[self handleNotificationOpened:messageDict actionType:type];
563563
} else if (isPreview && [OSDeviceUtils isIOSVersionGreaterThanOrEqual:@"10.0"]) {
564564
let notification = [OSNotification parseWithApns:messageDict];
565-
//[OneSignalHelper handleIAMPreview:notification]; //TODO: setup a notification center notif for this
565+
[self handleIAMPreview:notification];
566566
}
567567
}
568568

@@ -738,10 +738,9 @@ + (BOOL)clearBadgeCount:(BOOL)fromNotifOpened {
738738
+ (BOOL)handleIAMPreview:(OSNotification *)notification {
739739
NSString *uuid = [notification additionalData][ONESIGNAL_IAM_PREVIEW];
740740
if (uuid) {
741-
742741
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"IAM Preview Detected, Begin Handling"];
743-
// OSInAppMessageInternal *message = [OSInAppMessageInternal instancePreviewFromNotification:notification];
744-
// [[OSMessagingController sharedInstance] presentInAppPreviewMessage:message]; //TODO: Post to notification center for IAM to handle
742+
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:notification forKey:@"notification"];
743+
[[NSNotificationCenter defaultCenter] postNotificationName:ONESIGNAL_POST_PREVIEW_IAM object:nil userInfo:userInfo];
745744
return YES;
746745
}
747746
return NO;

iOS_SDK/OneSignalSDK/Source/OSMessagingController.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ NS_ASSUME_NONNULL_BEGIN
5151
+ (void)start;
5252
+ (void)removeInstance;
5353
- (void)presentInAppMessage:(OSInAppMessageInternal *)message;
54-
- (void)presentInAppPreviewMessage:(OSInAppMessageInternal *)message;
5554
- (void)updateInAppMessagesFromCache;
5655
- (void)getInAppMessagesFromServer:(NSString * _Nullable)subscriptionId;
5756
- (void)messageViewImpressionRequest:(OSInAppMessageInternal *)message;

iOS_SDK/OneSignalSDK/Source/OSMessagingController.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ - (instancetype)init {
159159
self.isAppInactive = NO;
160160
// BOOL that controls if in-app messaging is paused or not (false by default)
161161
_isInAppMessagingPaused = false;
162+
163+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleIAMPreview:) name:ONESIGNAL_POST_PREVIEW_IAM object:nil];
162164
}
163165

164166
return self;
@@ -311,6 +313,12 @@ - (void)onDidDismissInAppMessage:(OSInAppMessageInternal *)message {
311313
}
312314
}
313315

316+
- (void)handleIAMPreview:(NSNotification *)nsNotification {
317+
OSNotification *notification = [nsNotification.userInfo objectForKey:@"notification"];
318+
OSInAppMessageInternal *message = [OSInAppMessageInternal instancePreviewFromNotification:notification];
319+
[self presentInAppPreviewMessage:message];
320+
}
321+
314322
- (void)presentInAppMessage:(OSInAppMessageInternal *)message {
315323
if (!message.variantId) {
316324
let errorMessage = [NSString stringWithFormat:@"Attempted to display a message with a nil variantId. Current preferred language is %@, supported message variants are %@", OneSignalUserManagerImpl.sharedInstance.language, message.variants];
@@ -982,6 +990,10 @@ - (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChan
982990
[self getInAppMessagesFromServer:stateChanges.to.id];
983991
}
984992

993+
- (void)dealloc {
994+
[[NSNotificationCenter defaultCenter] removeObserver:self];
995+
}
996+
985997
@end
986998

987999
@implementation DummyOSMessagingController

0 commit comments

Comments
 (0)