Skip to content

Commit

Permalink
Merge pull request #977 from OneSignal/feature/IAM_lifecycle_events
Browse files Browse the repository at this point in the history
IAM lifecycle events
  • Loading branch information
emawby authored Aug 30, 2021
2 parents 7644e86 + 97f0ef6 commit 7673c5a
Show file tree
Hide file tree
Showing 28 changed files with 446 additions and 196 deletions.
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#import <UIKit/UIKit.h>
#import <OneSignal/OneSignal.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, OSPermissionObserver, OSSubscriptionObserver, OSEmailSubscriptionObserver>
@interface AppDelegate : UIResponder <UIApplicationDelegate, OSPermissionObserver, OSSubscriptionObserver, OSEmailSubscriptionObserver, OSInAppMessageLifecycleHandler>

@property (strong, nonatomic) UIWindow *window;

Expand Down
31 changes: 30 additions & 1 deletion iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[OneSignal addPermissionObserver:self];
[OneSignal addSubscriptionObserver:self];
[OneSignal addEmailSubscriptionObserver:self];

[OneSignal setInAppMessageLifecycleHandler:self];
[OneSignal pauseInAppMessages:true];

[OneSignal setNotificationWillShowInForegroundHandler:notificationReceiverBlock];
Expand Down Expand Up @@ -126,6 +126,35 @@ - (void)onOSEmailSubscriptionChanged:(OSEmailSubscriptionStateChanges *)stateCha
NSLog(@"onOSEmailSubscriptionChanged: %@", stateChanges);
}

#pragma mark OSInAppMessageDelegate

- (void)handleMessageAction:(OSInAppMessageAction *)action {
NSLog(@"OSInAppMessageDelegate: handling message action: %@",action);
return;
}

- (void)onWillDisplayInAppMessage:(OSInAppMessage *)message {
NSLog(@"OSInAppMessageDelegate: onWillDisplay Message: %@",message);
return;
}

- (void)onDidDisplayInAppMessage:(OSInAppMessage *)message {
NSLog(@"OSInAppMessageDelegate: onDidDisplay Message: %@",message);
return;
}

- (void)onWillDismissInAppMessage:(OSInAppMessage *)message {
NSLog(@"OSInAppMessageDelegate: onWillDismiss Message: %@",message);
return;
}

- (void)onDidDismissInAppMessage:(OSInAppMessage *)message {
NSLog(@"OSInAppMessageDelegate: onDidDismiss Message: %@",message);
return;
}

#pragma mark UIApplicationDelegate methods

- (void)applicationWillResignActive:(UIApplication *)application {
}

Expand Down
24 changes: 12 additions & 12 deletions iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,10 @@
CACBAA9D218A6243000ACAA5 /* OSInAppMessageView.m in Sources */ = {isa = PBXBuildFile; fileRef = CACBAA92218A6242000ACAA5 /* OSInAppMessageView.m */; };
CACBAA9E218A6243000ACAA5 /* OSInAppMessageView.m in Sources */ = {isa = PBXBuildFile; fileRef = CACBAA92218A6242000ACAA5 /* OSInAppMessageView.m */; };
CACBAA9F218A6243000ACAA5 /* OSInAppMessageView.m in Sources */ = {isa = PBXBuildFile; fileRef = CACBAA92218A6242000ACAA5 /* OSInAppMessageView.m */; };
CACBAAA0218A6243000ACAA5 /* OSInAppMessage.h in Headers */ = {isa = PBXBuildFile; fileRef = CACBAA93218A6243000ACAA5 /* OSInAppMessage.h */; };
CACBAAA1218A6243000ACAA5 /* OSInAppMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = CACBAA94218A6243000ACAA5 /* OSInAppMessage.m */; };
CACBAAA2218A6243000ACAA5 /* OSInAppMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = CACBAA94218A6243000ACAA5 /* OSInAppMessage.m */; };
CACBAAA3218A6243000ACAA5 /* OSInAppMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = CACBAA94218A6243000ACAA5 /* OSInAppMessage.m */; };
CACBAAA0218A6243000ACAA5 /* OSInAppMessageInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = CACBAA93218A6243000ACAA5 /* OSInAppMessageInternal.h */; };
CACBAAA1218A6243000ACAA5 /* OSInAppMessageInternal.m in Sources */ = {isa = PBXBuildFile; fileRef = CACBAA94218A6243000ACAA5 /* OSInAppMessageInternal.m */; };
CACBAAA2218A6243000ACAA5 /* OSInAppMessageInternal.m in Sources */ = {isa = PBXBuildFile; fileRef = CACBAA94218A6243000ACAA5 /* OSInAppMessageInternal.m */; };
CACBAAA3218A6243000ACAA5 /* OSInAppMessageInternal.m in Sources */ = {isa = PBXBuildFile; fileRef = CACBAA94218A6243000ACAA5 /* OSInAppMessageInternal.m */; };
CACBAAA4218A6243000ACAA5 /* OSInAppMessageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CACBAA95218A6243000ACAA5 /* OSInAppMessageViewController.m */; };
CACBAAA5218A6243000ACAA5 /* OSInAppMessageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CACBAA95218A6243000ACAA5 /* OSInAppMessageViewController.m */; };
CACBAAA6218A6243000ACAA5 /* OSInAppMessageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CACBAA95218A6243000ACAA5 /* OSInAppMessageViewController.m */; };
Expand Down Expand Up @@ -818,8 +818,8 @@
CACBAA90218A6242000ACAA5 /* OSMessagingController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSMessagingController.h; sourceTree = "<group>"; };
CACBAA91218A6242000ACAA5 /* OSInAppMessageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageView.h; sourceTree = "<group>"; };
CACBAA92218A6242000ACAA5 /* OSInAppMessageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageView.m; sourceTree = "<group>"; };
CACBAA93218A6243000ACAA5 /* OSInAppMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSInAppMessage.h; sourceTree = "<group>"; };
CACBAA94218A6243000ACAA5 /* OSInAppMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessage.m; sourceTree = "<group>"; };
CACBAA93218A6243000ACAA5 /* OSInAppMessageInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageInternal.h; sourceTree = "<group>"; };
CACBAA94218A6243000ACAA5 /* OSInAppMessageInternal.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageInternal.m; sourceTree = "<group>"; };
CACBAA95218A6243000ACAA5 /* OSInAppMessageViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageViewController.m; sourceTree = "<group>"; };
CACBAAA7218A6280000ACAA5 /* OSJSONHandling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSJSONHandling.h; sourceTree = "<group>"; };
CACBAAA9218A65AE000ACAA5 /* InAppMessagingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InAppMessagingTests.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1413,8 +1413,8 @@
children = (
CA47439B2190FEA80020DC8C /* OSTrigger.h */,
CA47439C2190FEA80020DC8C /* OSTrigger.m */,
CACBAA93218A6243000ACAA5 /* OSInAppMessage.h */,
CACBAA94218A6243000ACAA5 /* OSInAppMessage.m */,
CACBAA93218A6243000ACAA5 /* OSInAppMessageInternal.h */,
CACBAA94218A6243000ACAA5 /* OSInAppMessageInternal.m */,
CAB269D721B0B6F000F8A43C /* OSInAppMessageAction.h */,
CAB269D821B0B6F000F8A43C /* OSInAppMessageAction.m */,
CAB269DD21B2038B00F8A43C /* OSInAppMessageBridgeEvent.h */,
Expand Down Expand Up @@ -1583,7 +1583,7 @@
7A1232A5235E179B002B6CE3 /* OSIndirectInfluence.h in Headers */,
91F58D7F1E7C7F5F0017D24D /* OneSignalNotificationSettingsIOS10.h in Headers */,
912412391E73342200E41FD7 /* OneSignalWebView.h in Headers */,
CACBAAA0218A6243000ACAA5 /* OSInAppMessage.h in Headers */,
CACBAAA0218A6243000ACAA5 /* OSInAppMessageInternal.h in Headers */,
91C7725E1E7CCE1000D612D0 /* OneSignalInternal.h in Headers */,
CAB269DF21B2038B00F8A43C /* OSInAppMessageBridgeEvent.h in Headers */,
9129C6BD1E89E7AB009CB6A0 /* OSSubscription.h in Headers */,
Expand Down Expand Up @@ -1884,7 +1884,7 @@
A6D7093D26962C95007B3347 /* OneSignalSetLanguageParameters.m in Sources */,
7AF9865E2447C13C00C36EAE /* OSInfluenceDataRepository.m in Sources */,
7AECE59E23675F6300537907 /* OSFocusTimeProcessorFactory.m in Sources */,
CACBAAA1218A6243000ACAA5 /* OSInAppMessage.m in Sources */,
CACBAAA1218A6243000ACAA5 /* OSInAppMessageInternal.m in Sources */,
CA63AFC32022670A00E340FB /* ReattemptRequest.m in Sources */,
912412221E73342200E41FD7 /* OneSignalLocation.m in Sources */,
CACBAAA4218A6243000ACAA5 /* OSInAppMessageViewController.m in Sources */,
Expand Down Expand Up @@ -1985,7 +1985,7 @@
A63E9E3C26742B5F00EA273E /* LanguageContext.m in Sources */,
7AC8D3A924993A0F0023EDE8 /* OSDeviceState.m in Sources */,
CA810FD2202BA97600A60FED /* OSEmailSubscription.m in Sources */,
CACBAAA2218A6243000ACAA5 /* OSInAppMessage.m in Sources */,
CACBAAA2218A6243000ACAA5 /* OSInAppMessageInternal.m in Sources */,
7A674F1C2360D82E001F9ACD /* OSBaseFocusTimeProcessor.m in Sources */,
7AF9868124497BE100C36EAE /* OSOutcomeEventsV1Repository.m in Sources */,
7AFE856C2368DDB80091D6A5 /* OSFocusCallParams.m in Sources */,
Expand Down Expand Up @@ -2112,7 +2112,7 @@
CAE2E5AA215D80380036FD32 /* OneSignalNotificationServiceExtensionHandler.m in Sources */,
4529DEDE1FA828E500CEAB1D /* NSDateOverrider.m in Sources */,
CA08FC871FE99BB4004C445F /* OneSignalClientOverrider.m in Sources */,
CACBAAA3218A6243000ACAA5 /* OSInAppMessage.m in Sources */,
CACBAAA3218A6243000ACAA5 /* OSInAppMessageInternal.m in Sources */,
7AF5174C24FE980400B076BC /* RemoteParamsTests.m in Sources */,
CACBAAA6218A6243000ACAA5 /* OSInAppMessageViewController.m in Sources */,
912412401E73342200E41FD7 /* UIApplicationDelegate+OneSignal.m in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageController.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
*/

#import <Foundation/Foundation.h>
#import "OSInAppMessage.h"
#import "OSInAppMessageInternal.h"
#import "OneSignalClient.h"

NS_ASSUME_NONNULL_BEGIN

@interface OSInAppMessage (OSInAppMessageController)
@interface OSInAppMessageInternal (OSInAppMessageController)

- (void)loadMessageHTMLContentWithResult:(OSResultSuccessBlock _Nullable)successBlock failure:(OSFailureBlock _Nullable)failureBlock;
- (void)loadPreviewMessageHTMLContentWithUUID:(NSString * _Nonnull)previewUUID success:(OSResultSuccessBlock _Nullable)successBlock failure:(OSFailureBlock _Nullable)failureBlock;
Expand Down
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalSDK/Source/OSInAppMessageController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#import "OSInAppMessagingDefines.h"


@implementation OSInAppMessage (OSInAppMessageController)
@implementation OSInAppMessageInternal (OSInAppMessageController)

- (void)loadMessageHTMLContentWithResult:(OSResultSuccessBlock _Nullable)successBlock failure:(OSFailureBlock _Nullable)failureBlock {
let variantId = [self variantId];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@

NS_ASSUME_NONNULL_BEGIN

@interface OSInAppMessage : NSObject <NSCoding, OSJSONDecodable, OSJSONEncodable>
@interface OSInAppMessageInternal : OSInAppMessage <NSCoding, OSJSONDecodable, OSJSONEncodable>

@property (strong, nonatomic, nonnull) NSString *messageId;
@property (strong, nonatomic, nonnull) NSDictionary<NSString *, NSDictionary <NSString *, NSString *> *> *variants;
@property (strong, nonatomic, nonnull) NSArray<NSArray <OSTrigger *> *> *triggers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@
* THE SOFTWARE.
*/

#import "OSInAppMessage.h"
#import "OSInAppMessageInternal.h"
#import "OneSignalHelper.h"
#import "OneSignalCommonDefines.h"

@interface OSInAppMessage ()
@implementation OSInAppMessage
@end

@interface OSInAppMessageInternal ()

@property (strong, nonatomic, nonnull) NSMutableSet <NSString *> *clickedClickIds;
@property (strong, nonatomic, nonnull) NSMutableSet <NSString *> *viewedPageIds;

@end

@implementation OSInAppMessage
@implementation OSInAppMessageInternal

- (instancetype)init {
if (self = [super init]) {
Expand Down Expand Up @@ -87,7 +90,7 @@ + (instancetype)instanceWithData:(NSData *)data {
}

+ (instancetype)instanceWithJson:(NSDictionary * _Nonnull)json {
let message = [OSInAppMessage new];
let message = [OSInAppMessageInternal new];

if (json[@"id"] && [json[@"id"] isKindOfClass:[NSString class]])
message.messageId = json[@"id"];
Expand Down Expand Up @@ -144,7 +147,7 @@ + (instancetype)instanceWithJson:(NSDictionary * _Nonnull)json {
}

+ (instancetype)instancePreviewFromNotification:(OSNotification *)notification {
let message = [OSInAppMessage new];
let message = [OSInAppMessageInternal new];
message.messageId = [notification additionalData][ONESIGNAL_IAM_PREVIEW];
message.isPreview = true;
return message;
Expand Down Expand Up @@ -191,11 +194,11 @@ - (BOOL)isEqual:(id)object {
return YES;
}

if (![object isKindOfClass:[OSInAppMessage class]]) {
if (![object isKindOfClass:[OSInAppMessageInternal class]]) {
return NO;
}

OSInAppMessage *iam = object;
OSInAppMessageInternal *iam = object;

return [self.messageId isEqualToString:iam.messageId];
}
Expand All @@ -205,7 +208,7 @@ - (NSUInteger)hash {
}

- (void)encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:_messageId forKey:@"messageId"];
[encoder encodeObject:self.messageId forKey:@"messageId"];
[encoder encodeObject:_variants forKey:@"variants"];
[encoder encodeObject:_triggers forKey:@"triggers"];
[encoder encodeObject:_displayStats forKey:@"displayStats"];
Expand All @@ -217,7 +220,7 @@ - (void)encodeWithCoder:(NSCoder *)encoder {

- (id)initWithCoder:(NSCoder *)decoder {
if (self = [super init]) {
_messageId = [decoder decodeObjectForKey:@"messageId"];
self.messageId = [decoder decodeObjectForKey:@"messageId"];
_variants = [decoder decodeObjectForKey:@"variants"];
_triggers = [decoder decodeObjectForKey:@"triggers"];
_displayStats = [decoder decodeObjectForKey:@"displayStats"];
Expand Down
4 changes: 2 additions & 2 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/

#import <UIKit/UIKit.h>
#import "OSInAppMessage.h"
#import "OSInAppMessageInternal.h"
#import <WebKit/WebKit.h>

NS_ASSUME_NONNULL_BEGIN
Expand All @@ -42,7 +42,7 @@ NS_ASSUME_NONNULL_BEGIN

@property (weak, nonatomic, nullable) id<OSInAppMessageViewDelegate> delegate;

- (instancetype _Nonnull)initWithMessage:(OSInAppMessage *)inAppMessage withScriptMessageHandler:(id<WKScriptMessageHandler>)messageHandler;
- (instancetype _Nonnull)initWithMessage:(OSInAppMessageInternal *)inAppMessage withScriptMessageHandler:(id<WKScriptMessageHandler>)messageHandler;
- (void)resetWebViewToMaxBoundsAndResizeHeight:(void (^) (NSNumber *newHeight)) completion;
- (void)setupWebViewConstraints;
- (void)loadReplacementURL:(NSURL *)url;
Expand Down
4 changes: 2 additions & 2 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

@interface OSInAppMessageView () <UIScrollViewDelegate, WKUIDelegate, WKNavigationDelegate>

@property (strong, nonatomic, nonnull) OSInAppMessage *message;
@property (strong, nonatomic, nonnull) OSInAppMessageInternal *message;
@property (strong, nonatomic, nonnull) WKWebView *webView;
@property (nonatomic) BOOL loaded;

Expand All @@ -44,7 +44,7 @@ @interface OSInAppMessageView () <UIScrollViewDelegate, WKUIDelegate, WKNavigati

@implementation OSInAppMessageView

- (instancetype _Nonnull)initWithMessage:(OSInAppMessage *)inAppMessage withScriptMessageHandler:(id<WKScriptMessageHandler>)messageHandler {
- (instancetype _Nonnull)initWithMessage:(OSInAppMessageInternal *)inAppMessage withScriptMessageHandler:(id<WKScriptMessageHandler>)messageHandler {
if (self = [super init]) {
self.message = inAppMessage;
self.translatesAutoresizingMaskIntoConstraints = false;
Expand Down
19 changes: 11 additions & 8 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "OSInAppMessage.h"
#import "OSInAppMessageInternal.h"
#import "OSInAppMessageView.h"
#import "OSInAppMessageAction.h"
#import <WebKit/WebKit.h>
Expand All @@ -36,22 +36,25 @@ NS_ASSUME_NONNULL_BEGIN

@protocol OSInAppMessageViewControllerDelegate <NSObject>

- (void)messageViewDidSelectAction:(OSInAppMessage *)message withAction:(OSInAppMessageAction *)action;
- (void)messageViewDidDisplayPage:(OSInAppMessage *)message withPageId:(NSString *)pageId;
- (void)messageViewControllerWasDismissed;
- (void)webViewContentFinishedLoading:(OSInAppMessage *)message;
- (void)messageIsNotActive:(OSInAppMessage *)message;
- (void)messageViewDidSelectAction:(OSInAppMessageInternal *)message withAction:(OSInAppMessageAction *)action;
- (void)messageViewDidDisplayPage:(OSInAppMessageInternal *)message withPageId:(NSString *)pageId;
- (void)messageViewControllerDidDisplay:(OSInAppMessageInternal *)message;
- (void)messageViewControllerWillDismiss:(OSInAppMessageInternal *)message;
- (void)messageViewControllerWasDismissed:(OSInAppMessageInternal *)message displayed:(BOOL)displayed;
- (void)webViewContentFinishedLoading:(OSInAppMessageInternal *)message;
- (void)messageIsNotActive:(OSInAppMessageInternal *)message;
- (void)messageWillDisplay:(OSInAppMessageInternal *)message;

@end


@interface OSInAppMessageViewController : UIViewController <OSInAppMessageViewDelegate, WKScriptMessageHandler>

@property (weak, nonatomic, nullable) id<OSInAppMessageViewControllerDelegate> delegate;
@property (strong, nonatomic, nonnull) OSInAppMessage *message;
@property (strong, nonatomic, nonnull) OSInAppMessageInternal *message;
@property (nonatomic) BOOL waitForTags;

- (instancetype _Nonnull)initWithMessage:(OSInAppMessage *)inAppMessage delegate:(id<OSInAppMessageViewControllerDelegate>)delegate;
- (instancetype _Nonnull)initWithMessage:(OSInAppMessageInternal *)inAppMessage delegate:(id<OSInAppMessageViewControllerDelegate>)delegate;
- (void)dismissCurrentInAppMessage;

@end
Expand Down
Loading

0 comments on commit 7673c5a

Please sign in to comment.