diff --git a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h index 7f778546f..7e651874c 100644 --- a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h +++ b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h @@ -31,7 +31,7 @@ #import #import -@interface AppDelegate : UIResponder +@interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; diff --git a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m index d702bf2dd..78a333635 100644 --- a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m +++ b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m @@ -57,25 +57,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( _notificationDelegate = [OneSignalNotificationCenterDelegate new]; - id openNotificationHandler = ^(OSNotificationOpenedResult *result) { - // TODO: opened handler Not triggered - NSLog(@"OSNotificationOpenedResult: %@", result.action); - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated" - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notifiation Opened In App Delegate" message:@"Notification Opened In App Delegate" delegate:self cancelButtonTitle:@"Delete" otherButtonTitles:@"Cancel", nil]; - [alert show]; - #pragma clang diagnostic pop - }; - - // Example block for IAM action click handler - id inAppMessagingActionClickBlock = ^(OSInAppMessageAction *action) { - NSString *message = [NSString stringWithFormat:@"Click Action Occurred: %@", [action jsonRepresentation]]; - [OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:message]; - }; - - // Example setter for IAM action click handler using OneSignal public method - [OneSignal.InAppMessages setClickHandler:inAppMessagingActionClickBlock]; - // OneSignal Init with app id and lauch options [OneSignal setLaunchURLsInApp:YES]; [OneSignal setProvidesNotificationSettingsView:NO]; @@ -84,13 +65,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [OneSignal.InAppMessages paused:true]; [OneSignal.Notifications addForegroundLifecycleListener:self]; - [OneSignal.Notifications setNotificationOpenedHandler:openNotificationHandler]; - + [OneSignal.Notifications addClickListener:self]; [OneSignal.User.pushSubscription addObserver:self]; NSLog(@"OneSignal Demo App push subscription observer added"); [OneSignal.Notifications addPermissionObserver:self]; - + [OneSignal.InAppMessages addClickListener:self]; + NSLog(@"UNUserNotificationCenter.delegate: %@", UNUserNotificationCenter.currentNotificationCenter.delegate); return YES; @@ -117,17 +98,20 @@ - (void)onNotificationPermissionDidChange:(BOOL)permission { NSLog(@"Dev App onNotificationPermissionDidChange: %d", permission); } -- (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChanges *)stateChanges { - NSLog(@"Dev App onOSPushSubscriptionChangedWithStateChanges: %@", stateChanges); +- (void)onPushSubscriptionDidChangeWithState:(OSPushSubscriptionChangedState *)state { + NSLog(@"Dev App onPushSubscriptionDidChange: %@", state); ViewController* mainController = (ViewController*) self.window.rootViewController; - mainController.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) stateChanges.to.optedIn; + mainController.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) state.current.optedIn; +} + +- (void)onClickNotification:(OSNotificationClickEvent * _Nonnull)event { + NSLog(@"Dev App onClickNotification with event %@", [event jsonRepresentation]); } #pragma mark OSInAppMessageDelegate -- (void)handleMessageAction:(OSInAppMessageAction *)action { - NSLog(@"OSInAppMessageDelegate: handling message action: %@",action); - return; +- (void)onClickInAppMessage:(OSInAppMessageClickEvent * _Nonnull)event { + NSLog(@"Dev App onClickInAppMessage event: %@", [event jsonRepresentation]); } - (void)onWillDisplayNotification:(OSNotificationWillDisplayEvent *)event { @@ -139,22 +123,22 @@ - (void)onWillDisplayNotification:(OSNotificationWillDisplayEvent *)event { } - (void)onWillDisplayInAppMessage:(OSInAppMessageWillDisplayEvent *)event { - NSLog(@"OSInAppMessageDelegate: onWillDisplay Message: %@",event.message); + NSLog(@"Dev App OSInAppMessageLifecycleListener: onWillDisplay Message: %@",event.message); return; } - (void)onDidDisplayInAppMessage:(OSInAppMessageDidDisplayEvent *)event { - NSLog(@"OSInAppMessageDelegate: onDidDisplay Message: %@",event.message); + NSLog(@"Dev App OSInAppMessageLifecycleListener: onDidDisplay Message: %@",event.message); return; } - (void)onWillDismissInAppMessage:(OSInAppMessageWillDismissEvent *)event { - NSLog(@"OSInAppMessageDelegate: onWillDismiss Message: %@",event.message); + NSLog(@"Dev App OSInAppMessageLifecycleListener: onWillDismiss Message: %@",event.message); return; } - (void)onDidDismissInAppMessage:(OSInAppMessageDidDismissEvent *)event { - NSLog(@"OSInAppMessageDelegate: onDidDismiss Message: %@",event.message); + NSLog(@"Dev App OSInAppMessageLifecycleListener: onDidDismiss Message: %@",event.message); return; } diff --git a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.h b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.h index b80110dc7..57476c685 100644 --- a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.h +++ b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.h @@ -31,7 +31,7 @@ #import #import -@interface ViewController : UIViewController +@interface ViewController : UIViewController @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicatorView; @property (weak, nonatomic) IBOutlet UISegmentedControl *consentSegmentedControl; diff --git a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.m b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.m index 5a95554ce..1f186061e 100644 --- a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.m +++ b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.m @@ -190,10 +190,6 @@ - (IBAction)inAppMessagingSegmentedControlValueChanged:(UISegmentedControl *)sen [OneSignal.InAppMessages paused:(bool) !sender.selectedSegmentIndex]; } -- (void)handleMessageAction:(NSString *)actionId { - NSLog(@"View controller did get action: %@", actionId); -} - - (IBAction)loginExternalUserId:(UIButton *)sender { NSString* externalUserId = self.externalUserIdTextField.text; NSLog(@"Dev App: Logging in to external user ID %@", externalUserId); diff --git a/iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/AppDelegate.m b/iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/AppDelegate.m index d40d72e7c..7e11a86c5 100644 --- a/iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/AppDelegate.m +++ b/iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/AppDelegate.m @@ -54,20 +54,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [OneSignal.Debug setLogLevel:ONE_S_LL_VERBOSE]; [OneSignal.Debug setAlertLevel:ONE_S_LL_NONE]; _notificationDelegate = [OneSignalNotificationCenterDelegate new]; - - id openNotificationHandler = ^(OSNotificationOpenedResult *result) { - NSLog(@"OSNotificationOpenedResult: %@", result.action); - }; - - // Example block for IAM action click handler - id inAppMessagingActionClickBlock = ^(OSInAppMessageAction *action) { - NSString *message = [NSString stringWithFormat:@"Click Action Occurred: %@", [action jsonRepresentation]]; - [OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:message]; - }; - - // Example setter for IAM action click handler using OneSignal public method - [OneSignal.InAppMessages setClickHandler:inAppMessagingActionClickBlock]; - + // OneSignal Init with app id and lauch options [OneSignal setLaunchURLsInApp:YES]; [OneSignal setProvidesNotificationSettingsView:NO]; @@ -83,8 +70,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [OneSignal.InAppMessages paused:false]; - [OneSignal.Notifications setNotificationOpenedHandler:openNotificationHandler]; - NSLog(@"UNUserNotificationCenter.delegate: %@", UNUserNotificationCenter.currentNotificationCenter.delegate); return YES; diff --git a/iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/ViewController.h b/iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/ViewController.h index 956c2cacb..a1b63b9d7 100644 --- a/iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/ViewController.h +++ b/iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/ViewController.h @@ -31,7 +31,7 @@ #import #import -@interface ViewController : UIViewController +@interface ViewController : UIViewController @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicatorView; @property (weak, nonatomic) IBOutlet UISegmentedControl *consentSegmentedControl; diff --git a/iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/ViewController.m b/iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/ViewController.m index 5f84b4f07..b85520261 100644 --- a/iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/ViewController.m +++ b/iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/ViewController.m @@ -144,10 +144,6 @@ - (IBAction)inAppMessagingSegmentedControlValueChanged:(UISegmentedControl *)sen [OneSignal.InAppMessages paused:(bool) !sender.selectedSegmentIndex]; } -- (void)handleMessageAction:(NSString *)actionId { - NSLog(@"View controller did get action: %@", actionId); -} - - (IBAction)loginExternalUserId:(UIButton *)sender { NSLog(@"setExternalUserId is no longer supported. Please use login or addAlias."); // TODO: Update diff --git a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj index 1f82866c9..97bd5a501 100644 --- a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj +++ b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj @@ -78,6 +78,10 @@ 3C47A974292642B100312125 /* OneSignalConfigManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C47A972292642B100312125 /* OneSignalConfigManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3C47A975292642B100312125 /* OneSignalConfigManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C47A973292642B100312125 /* OneSignalConfigManager.m */; }; 3C4F9E4428A4466C009F453A /* OSOperationRepo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C4F9E4328A4466C009F453A /* OSOperationRepo.swift */; }; + 3C6302FA29FC7E17004FAEB3 /* OSInAppMessageClickEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C6302F929FC7E17004FAEB3 /* OSInAppMessageClickEvent.m */; }; + 3C6302FB29FC7EA3004FAEB3 /* OSInAppMessageClickEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C6302F829FC7E17004FAEB3 /* OSInAppMessageClickEvent.h */; }; + 3C6302FC29FC7EC6004FAEB3 /* OSInAppMessageClickEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C6302F929FC7E17004FAEB3 /* OSInAppMessageClickEvent.m */; }; + 3C6302FD29FC7EC7004FAEB3 /* OSInAppMessageClickEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C6302F929FC7E17004FAEB3 /* OSInAppMessageClickEvent.m */; }; 3C789DBD293C2206004CF83D /* OSFocusInfluenceParam.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A600B432453790700514A53 /* OSFocusInfluenceParam.m */; }; 3C789DBE293D8EAD004CF83D /* OSFocusInfluenceParam.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A600B41245378ED00514A53 /* OSFocusInfluenceParam.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3C79BEB9293DC88F0034CB10 /* OneSignalInAppMessaging.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C79BEB7293DC88F0034CB10 /* OneSignalInAppMessaging.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -256,10 +260,10 @@ CA8E190B2194FE0B009DA223 /* OSMessagingControllerOverrider.m in Sources */ = {isa = PBXBuildFile; fileRef = CA8E190A2194FE0B009DA223 /* OSMessagingControllerOverrider.m */; }; CAA4ED0120646762005BD59B /* BadgeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CAA4ED0020646762005BD59B /* BadgeTests.m */; }; CAAE0DFD2195216900A57402 /* OneSignalOverrider.m in Sources */ = {isa = PBXBuildFile; fileRef = CAAE0DFC2195216900A57402 /* OneSignalOverrider.m */; }; - CAB269D921B0B6F000F8A43C /* OSInAppMessageAction.h in Headers */ = {isa = PBXBuildFile; fileRef = CAB269D721B0B6F000F8A43C /* OSInAppMessageAction.h */; }; - CAB269DA21B0B6F000F8A43C /* OSInAppMessageAction.m in Sources */ = {isa = PBXBuildFile; fileRef = CAB269D821B0B6F000F8A43C /* OSInAppMessageAction.m */; }; - CAB269DB21B0B6F000F8A43C /* OSInAppMessageAction.m in Sources */ = {isa = PBXBuildFile; fileRef = CAB269D821B0B6F000F8A43C /* OSInAppMessageAction.m */; }; - CAB269DC21B0B6F000F8A43C /* OSInAppMessageAction.m in Sources */ = {isa = PBXBuildFile; fileRef = CAB269D821B0B6F000F8A43C /* OSInAppMessageAction.m */; }; + CAB269D921B0B6F000F8A43C /* OSInAppMessageClickResult.h in Headers */ = {isa = PBXBuildFile; fileRef = CAB269D721B0B6F000F8A43C /* OSInAppMessageClickResult.h */; }; + CAB269DA21B0B6F000F8A43C /* OSInAppMessageClickResult.m in Sources */ = {isa = PBXBuildFile; fileRef = CAB269D821B0B6F000F8A43C /* OSInAppMessageClickResult.m */; }; + CAB269DB21B0B6F000F8A43C /* OSInAppMessageClickResult.m in Sources */ = {isa = PBXBuildFile; fileRef = CAB269D821B0B6F000F8A43C /* OSInAppMessageClickResult.m */; }; + CAB269DC21B0B6F000F8A43C /* OSInAppMessageClickResult.m in Sources */ = {isa = PBXBuildFile; fileRef = CAB269D821B0B6F000F8A43C /* OSInAppMessageClickResult.m */; }; CAB269DF21B2038B00F8A43C /* OSInAppMessageBridgeEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = CAB269DD21B2038B00F8A43C /* OSInAppMessageBridgeEvent.h */; }; CAB269E021B2038B00F8A43C /* OSInAppMessageBridgeEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = CAB269DE21B2038B00F8A43C /* OSInAppMessageBridgeEvent.m */; }; CAB269E121B2038B00F8A43C /* OSInAppMessageBridgeEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = CAB269DE21B2038B00F8A43C /* OSInAppMessageBridgeEvent.m */; }; @@ -682,6 +686,8 @@ 3C47A972292642B100312125 /* OneSignalConfigManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalConfigManager.h; sourceTree = ""; }; 3C47A973292642B100312125 /* OneSignalConfigManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalConfigManager.m; sourceTree = ""; }; 3C4F9E4328A4466C009F453A /* OSOperationRepo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSOperationRepo.swift; sourceTree = ""; }; + 3C6302F829FC7E17004FAEB3 /* OSInAppMessageClickEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageClickEvent.h; sourceTree = ""; }; + 3C6302F929FC7E17004FAEB3 /* OSInAppMessageClickEvent.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageClickEvent.m; sourceTree = ""; }; 3C79BEB7293DC88F0034CB10 /* OneSignalInAppMessaging.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalInAppMessaging.h; sourceTree = ""; }; 3C79BEB8293DC88F0034CB10 /* OneSignalInAppMessaging.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalInAppMessaging.m; sourceTree = ""; }; 3C8E6DF828A6D89E0031E48A /* OSOperationExecutor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSOperationExecutor.swift; sourceTree = ""; }; @@ -898,8 +904,8 @@ CAAE0DFC2195216900A57402 /* OneSignalOverrider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalOverrider.m; sourceTree = ""; }; CAAEA68521ED68A30049CF15 /* OneSignalNotificationCategoryController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OneSignalNotificationCategoryController.m; sourceTree = ""; }; CAAEA68621ED68A40049CF15 /* OneSignalNotificationCategoryController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OneSignalNotificationCategoryController.h; sourceTree = ""; }; - CAB269D721B0B6F000F8A43C /* OSInAppMessageAction.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageAction.h; sourceTree = ""; }; - CAB269D821B0B6F000F8A43C /* OSInAppMessageAction.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageAction.m; sourceTree = ""; }; + CAB269D721B0B6F000F8A43C /* OSInAppMessageClickResult.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageClickResult.h; sourceTree = ""; }; + CAB269D821B0B6F000F8A43C /* OSInAppMessageClickResult.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageClickResult.m; sourceTree = ""; }; CAB269DD21B2038B00F8A43C /* OSInAppMessageBridgeEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageBridgeEvent.h; sourceTree = ""; }; CAB269DE21B2038B00F8A43C /* OSInAppMessageBridgeEvent.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageBridgeEvent.m; sourceTree = ""; }; CAB4112720852E48005A70D1 /* DelayedConsentInitializationParameters.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DelayedConsentInitializationParameters.h; sourceTree = ""; }; @@ -1469,8 +1475,10 @@ CA47439C2190FEA80020DC8C /* OSTrigger.m */, CACBAA93218A6243000ACAA5 /* OSInAppMessageInternal.h */, CACBAA94218A6243000ACAA5 /* OSInAppMessageInternal.m */, - CAB269D721B0B6F000F8A43C /* OSInAppMessageAction.h */, - CAB269D821B0B6F000F8A43C /* OSInAppMessageAction.m */, + 3C6302F829FC7E17004FAEB3 /* OSInAppMessageClickEvent.h */, + 3C6302F929FC7E17004FAEB3 /* OSInAppMessageClickEvent.m */, + CAB269D721B0B6F000F8A43C /* OSInAppMessageClickResult.h */, + CAB269D821B0B6F000F8A43C /* OSInAppMessageClickResult.m */, CAB269DD21B2038B00F8A43C /* OSInAppMessageBridgeEvent.h */, CAB269DE21B2038B00F8A43C /* OSInAppMessageBridgeEvent.m */, 7A72EB1123E252D400B4D50F /* OSInAppMessageDisplayStats.h */, @@ -1975,6 +1983,7 @@ CA4742E4218B8FF30020DC8C /* OSTriggerController.h in Headers */, DE7D18EC2703B5AA002D3A5D /* OSInAppMessagingRequests.h in Headers */, DE16C14724D3727200670EFA /* OneSignalLifecycleObserver.h in Headers */, + 3C6302FB29FC7EA3004FAEB3 /* OSInAppMessageClickEvent.h in Headers */, DE51DDE12941697A0073D5C4 /* OneSignalLocation.h in Headers */, 7A674F192360D813001F9ACD /* OSBaseFocusTimeProcessor.h in Headers */, CA36F35821C33A2500300C77 /* OSInAppMessageController.h in Headers */, @@ -1989,7 +1998,7 @@ 9124123D1E73342200E41FD7 /* UIApplicationDelegate+OneSignal.h in Headers */, 7AF9865324451F3900C36EAE /* OSFocusCallParams.h in Headers */, DE7D18DD2703B44B002D3A5D /* OSFocusRequests.h in Headers */, - CAB269D921B0B6F000F8A43C /* OSInAppMessageAction.h in Headers */, + CAB269D921B0B6F000F8A43C /* OSInAppMessageClickResult.h in Headers */, DEE8198D24E21DF000868CBA /* UIApplication+OneSignal.h in Headers */, 7AECE59C23675F5700537907 /* OSFocusTimeProcessorFactory.h in Headers */, 7AECE59A23674ADC00537907 /* OSUnattributedFocusTimeProcessor.h in Headers */, @@ -2543,6 +2552,7 @@ 7A1F2D8F2406EFC5007799A9 /* OSInAppMessageTag.m in Sources */, 7A72EB0E23E252C200B4D50F /* OSInAppMessageDisplayStats.m in Sources */, 9124121E1E73342200E41FD7 /* OneSignalJailbreakDetection.m in Sources */, + 3C6302FA29FC7E17004FAEB3 /* OSInAppMessageClickEvent.m in Sources */, 912412471E73369600E41FD7 /* OneSignalHelper.m in Sources */, 7A880F312404AE7B0081F5E8 /* OSInAppMessagePushPrompt.m in Sources */, CA8E19062193C76D009DA223 /* OSInAppMessagingHelpers.m in Sources */, @@ -2574,7 +2584,7 @@ 7AECE59023674A9700537907 /* OSAttributedFocusTimeProcessor.m in Sources */, 912412361E73342200E41FD7 /* OneSignalTrackIAP.m in Sources */, CACBAA9D218A6243000ACAA5 /* OSInAppMessageView.m in Sources */, - CAB269DA21B0B6F000F8A43C /* OSInAppMessageAction.m in Sources */, + CAB269DA21B0B6F000F8A43C /* OSInAppMessageClickResult.m in Sources */, CA1A6E6A20DC2E31001C41B9 /* OneSignalDialogController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2633,6 +2643,7 @@ 7A674F1C2360D82E001F9ACD /* OSBaseFocusTimeProcessor.m in Sources */, 7AFE856C2368DDB80091D6A5 /* OSFocusCallParams.m in Sources */, CACBAAA5218A6243000ACAA5 /* OSInAppMessageViewController.m in Sources */, + 3C6302FC29FC7EC6004FAEB3 /* OSInAppMessageClickEvent.m in Sources */, CA7FC8A121927229002C4FD9 /* OSDynamicTriggerController.m in Sources */, 912412231E73342200E41FD7 /* OneSignalLocation.m in Sources */, 7A93269D25AF4F0200BBEC27 /* OSPendingCallbacks.m in Sources */, @@ -2641,7 +2652,7 @@ 912412371E73342200E41FD7 /* OneSignalTrackIAP.m in Sources */, 7AECE59123674A9700537907 /* OSAttributedFocusTimeProcessor.m in Sources */, CACBAA9E218A6243000ACAA5 /* OSInAppMessageView.m in Sources */, - CAB269DB21B0B6F000F8A43C /* OSInAppMessageAction.m in Sources */, + CAB269DB21B0B6F000F8A43C /* OSInAppMessageClickResult.m in Sources */, 3C79BEBA293DC88F0034CB10 /* OneSignalInAppMessaging.m in Sources */, CA1A6E6B20DC2E31001C41B9 /* OneSignalDialogController.m in Sources */, ); @@ -2672,7 +2683,7 @@ 4529DEED1FA83C5D00CEAB1D /* OneSignalHelperOverrider.m in Sources */, CA1A6E6C20DC2E31001C41B9 /* OneSignalDialogController.m in Sources */, 7A65D62A246627AD007FF196 /* OSInAppMessageViewOverrider.m in Sources */, - CAB269DC21B0B6F000F8A43C /* OSInAppMessageAction.m in Sources */, + CAB269DC21B0B6F000F8A43C /* OSInAppMessageClickResult.m in Sources */, DE16C17024D3989A00670EFA /* OneSignalLifecycleObserver.m in Sources */, CAAE0DFD2195216900A57402 /* OneSignalOverrider.m in Sources */, 912412241E73342200E41FD7 /* OneSignalLocation.m in Sources */, @@ -2743,6 +2754,7 @@ 03CCCC832835D90F004BF794 /* OneSignalUNUserNotificationCenterHelper.m in Sources */, 03866CC12378A67B0009C1D8 /* RestClientAsserts.m in Sources */, 7ADF891C230DB5BD0054E0D6 /* UnitTestAppDelegate.m in Sources */, + 3C6302FD29FC7EC7004FAEB3 /* OSInAppMessageClickEvent.m in Sources */, 4529DEF01FA8433500CEAB1D /* NSLocaleOverrider.m in Sources */, CA1A6E7220DC2E73001C41B9 /* OneSignalDialogRequest.m in Sources */, 7A880F332404AE7B0081F5E8 /* OSInAppMessagePushPrompt.m in Sources */, diff --git a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSNotificationClasses.h b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSNotificationClasses.h index 85dcb7cdb..dd4a8ce18 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSNotificationClasses.h +++ b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSNotificationClasses.h @@ -36,20 +36,17 @@ typedef NS_ENUM(NSUInteger, OSNotificationActionType) { OSNotificationActionTypeActionTaken }; -@interface OSNotificationAction : NSObject - -/* The type of the notification action */ -@property(readonly)OSNotificationActionType type; - +@interface OSNotificationClickResult : NSObject /* The ID associated with the button tapped. NULL when the actionType is NotificationTapped */ @property(readonly, nullable)NSString* actionId; +@property(readonly, nullable)NSString* url; @end -@interface OSNotificationOpenedResult : NSObject +@interface OSNotificationClickEvent : NSObject @property(readonly, nonnull)OSNotification* notification; -@property(readonly, nonnull)OSNotificationAction *action; +@property(readonly, nonnull)OSNotificationClickResult *result; /* Convert object into an NSString that can be convertible into a custom Dictionary / JSON Object */ - (NSString* _Nonnull)stringify; diff --git a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalTrackFirebaseAnalytics.h b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalTrackFirebaseAnalytics.h index b40a02eb5..948541aaf 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalTrackFirebaseAnalytics.h +++ b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalTrackFirebaseAnalytics.h @@ -33,7 +33,7 @@ +(void)init; +(void)updateFromDownloadParams:(NSDictionary*)params; -+(void)trackOpenEvent:(OSNotificationOpenedResult*)results; ++(void)trackOpenEvent:(OSNotificationClickEvent*)event; +(void)trackReceivedEvent:(OSNotification*)notification; +(void)trackInfluenceOpenEvent; @end diff --git a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalTrackFirebaseAnalytics.m b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalTrackFirebaseAnalytics.m index 4ce221826..0c4432ea5 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalTrackFirebaseAnalytics.m +++ b/iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalTrackFirebaseAnalytics.m @@ -87,7 +87,7 @@ + (NSString*)getCampaignNameFromNotification:(OSNotification *)notification { return [notification.title substringToIndex:titleLength]; } -+ (void)trackOpenEvent:(OSNotificationOpenedResult*)results { ++ (void)trackOpenEvent:(OSNotificationClickEvent*)event { if (!trackingEnabled) return; @@ -97,8 +97,8 @@ + (void)trackOpenEvent:(OSNotificationOpenedResult*)results { parameters:@{ @"source": @"OneSignal", @"medium": @"notification", - @"notification_id": results.notification.notificationId, - @"campaign": [self getCampaignNameFromNotification:results.notification] + @"notification_id": event.notification.notificationId, + @"campaign": [self getCampaignNameFromNotification:event.notification] }]; } diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h index 63a031a92..6c99c2f66 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h @@ -32,7 +32,10 @@ #import #import -typedef void (^OSNotificationOpenedBlock)(OSNotificationOpenedResult * _Nonnull result); +@protocol OSNotificationClickListener +- (void)onClickNotification:(OSNotificationClickEvent *_Nonnull)event +NS_SWIFT_NAME(onClick(event:)); +@end @interface OSNotificationWillDisplayEvent : NSObject @@ -54,8 +57,8 @@ typedef void (^OSNotificationOpenedBlock)(OSNotificationOpenedResult * _Nonnull + (OSNotificationPermission)permissionNative NS_REFINED_FOR_SWIFT; + (void)addForegroundLifecycleListener:(NSObject *_Nullable)listener; + (void)removeForegroundLifecycleListener:(NSObject *_Nullable)listener; - -+ (void)setNotificationOpenedHandler:(OSNotificationOpenedBlock _Nullable)block; ++ (void)addClickListener:(NSObject*_Nonnull)listener NS_REFINED_FOR_SWIFT; ++ (void)removeClickListener:(NSObject*_Nonnull)listener NS_REFINED_FOR_SWIFT; + (void)requestPermission:(OSUserResponseBlock _Nullable )block; + (void)requestPermission:(OSUserResponseBlock _Nullable )block fallbackToSettings:(BOOL)fallback; + (void)registerForProvisionalAuthorization:(OSUserResponseBlock _Nullable )block NS_REFINED_FOR_SWIFT; @@ -111,8 +114,7 @@ typedef void (^OSNotificationOpenedBlock)(OSNotificationOpenedResult * _Nonnull + (void)setPushSubscriptionId:(NSString *_Nullable)pushSubscriptionId; + (void)handleWillShowInForegroundForNotification:(OSNotification *_Nonnull)notification completion:(OSNotificationDisplayResponse _Nonnull)completion; -+ (void)handleNotificationAction:(OSNotificationActionType)actionType actionID:(NSString* _Nonnull)actionID; - ++ (void)handleNotificationActionWithUrl:(NSString* _Nullable)url actionID:(NSString* _Nonnull)actionID; + (BOOL)clearBadgeCount:(BOOL)fromNotifOpened; + (BOOL)receiveRemoteNotification:(UIApplication* _Nonnull)application UserInfo:(NSDictionary* _Nonnull)userInfo completionHandler:(void (^_Nonnull)(UIBackgroundFetchResult))completionHandler; diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m index 003b2fdb9..c06748df1 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m @@ -35,14 +35,14 @@ of this software and associated documentation files (the "Software"), to deal #import "UNUserNotificationCenter+OneSignalNotifications.h" #import "UIApplicationDelegate+OneSignalNotifications.h" -@implementation OSNotificationOpenedResult -@synthesize notification = _notification, action = _action; +@implementation OSNotificationClickEvent +@synthesize notification = _notification, result = _result; -- (id)initWithNotification:(OSNotification*)notification action:(OSNotificationAction*)action { +- (id)initWithNotification:(OSNotification*)notification result:(OSNotificationClickResult*)result { self = [super init]; if(self) { _notification = notification; - _action = action; + _result = result; } return self; } @@ -63,25 +63,24 @@ - (NSDictionary *_Nonnull)jsonRepresentation { error:&jsonError]; NSMutableDictionary* obj = [NSMutableDictionary new]; - NSMutableDictionary* action = [NSMutableDictionary new]; - [action setObject:self.action.actionId forKeyedSubscript:@"actionID"]; - [obj setObject:action forKeyedSubscript:@"action"]; + NSMutableDictionary* result = [NSMutableDictionary new]; + [result setObject:self.result.actionId forKeyedSubscript:@"actionID"]; + [result setObject:self.result.url forKeyedSubscript:@"url"]; + [obj setObject:result forKeyedSubscript:@"result"]; [obj setObject:notifDict forKeyedSubscript:@"notification"]; - if(self.action.type) - [obj[@"action"] setObject:@(self.action.type) forKeyedSubscript: @"type"]; - + return obj; } @end -@implementation OSNotificationAction -@synthesize type = _type, actionId = _actionId; +@implementation OSNotificationClickResult +@synthesize url = _url, actionId = _actionId; --(id)initWithActionType:(OSNotificationActionType)type :(NSString*)actionID { +-(id)initWithUrl:(NSString*)url :(NSString*)actionID { self = [super init]; if(self) { - _type = type; + _url = url; _actionId = actionID; } return self; @@ -149,8 +148,14 @@ + (void)setLifecycleListener:(id)lifecycleListe static int mSubscriptionStatus = -1; -static NSMutableArray *_unprocessedOpenedNotifis; -static OSNotificationOpenedBlock _notificationOpenedHandler; +static NSMutableArray *_unprocessedClickEvents; +static NSMutableArray *> *_clickListeners; ++ (NSMutableArray *>*)clickListeners { + if (!_clickListeners) + _clickListeners = [NSMutableArray new]; + return _clickListeners; +} + static NSDictionary* _lastMessageReceived; static NSString *_lastMessageID = @""; static NSString *_lastMessageIdFromAction; @@ -255,7 +260,7 @@ + (void)resetLocals { _lastMessageReceived = nil; _lastMessageIdFromAction = nil; _lastMessageID = @""; - _unprocessedOpenedNotifis = nil; + _unprocessedClickEvents = nil; } + (void)setLastPermissionState:(OSPermissionStateInternal *)lastPermissionState { @@ -693,7 +698,7 @@ + (void)handleNotificationOpened:(NSDictionary*)messageDict // [[OSSessionManager sharedSessionManager] onDirectInfluenceFromNotificationOpen:_appEntryState withNotificationId:messageId]; // } - [self handleNotificationAction:actionType actionID:actionID]; + [self handleNotificationActionWithUrl:notification.launchURL actionID:actionID]; } + (void)submitNotificationOpened:(NSString*)messageId { @@ -793,28 +798,35 @@ + (BOOL)handleIAMPreview:(OSNotification *)notification { return NO; } -+ (void)handleNotificationAction:(OSNotificationActionType)actionType actionID:(NSString*)actionID { ++ (void)handleNotificationActionWithUrl:(NSString*)url actionID:(NSString*)actionID { if (![OneSignalCoreHelper isOneSignalPayload:_lastMessageReceived]) return; - OSNotificationAction *action = [[OSNotificationAction alloc] initWithActionType:actionType :actionID]; + OSNotificationClickResult *result = [[OSNotificationClickResult alloc] initWithUrl:url :actionID]; OSNotification *notification = [OSNotification parseWithApns:_lastMessageReceived]; - OSNotificationOpenedResult *result = [[OSNotificationOpenedResult alloc] initWithNotification:notification action:action]; + OSNotificationClickEvent *event = [[OSNotificationClickEvent alloc] initWithNotification:notification result:result]; // Prevent duplicate calls to same action if ([notification.notificationId isEqualToString:_lastMessageIdFromAction]) return; _lastMessageIdFromAction = notification.notificationId; - [OneSignalTrackFirebaseAnalytics trackOpenEvent:result]; - - if (!_notificationOpenedHandler) { - [self addUnprocessedOpenedNotifi:result]; + [OneSignalTrackFirebaseAnalytics trackOpenEvent:event]; + + if (self.clickListeners.count == 0) { + [self addUnprocessedClickEvent:event]; return; } - _notificationOpenedHandler(result); + [self fireClickListenersForEvent:event]; } ++ (void)fireClickListenersForEvent:(OSNotificationClickEvent*)event { + for (NSObject *listener in self.clickListeners) { + if ([listener respondsToSelector:@selector(onClickNotification:)]) { + [listener onClickNotification:event]; + } + } +} + (void)lastMessageReceived:(NSDictionary*)message { _lastMessageReceived = message; @@ -828,11 +840,15 @@ + (BOOL)shouldSuppressURL { return shouldSuppress ?: false; } -+ (void)setNotificationOpenedHandler:(OSNotificationOpenedBlock)block { - _notificationOpenedHandler = block; - [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"Notification opened handler set successfully"]; - [self fireNotificationOpenedHandlerForUnprocessedEvents]; - ++ (void)addClickListener:(NSObject*)listener { + [self.clickListeners addObject:listener]; + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"Notification click listener added successfully"]; + [self fireClickListenersForUnprocessedEvents]; +} + ++ (void)removeClickListener:(NSObject*)listener { + [self.clickListeners removeObject:listener]; + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"Notification click listener removed successfully"]; } + (void)addForegroundLifecycleListener:(NSObject *_Nullable)listener { @@ -845,24 +861,24 @@ + (void)removeForegroundLifecycleListener:(NSObject*)getUnprocessedOpenedNotifis { - if (!_unprocessedOpenedNotifis) - _unprocessedOpenedNotifis = [NSMutableArray new]; - return _unprocessedOpenedNotifis; ++ (NSMutableArray*)getUnprocessedClickEvents { + if (!_unprocessedClickEvents) + _unprocessedClickEvents = [NSMutableArray new]; + return _unprocessedClickEvents; } -+ (void)addUnprocessedOpenedNotifi:(OSNotificationOpenedResult*)result { - [[self getUnprocessedOpenedNotifis] addObject:result]; ++ (void)addUnprocessedClickEvent:(OSNotificationClickEvent*)event { + [[self getUnprocessedClickEvents] addObject:event]; } -+ (void)fireNotificationOpenedHandlerForUnprocessedEvents { - if (!_notificationOpenedHandler) ++ (void)fireClickListenersForUnprocessedEvents { + if (self.clickListeners.count == 0) { return; - - for (OSNotificationOpenedResult* notification in [self getUnprocessedOpenedNotifis]) { - _notificationOpenedHandler(notification); } - _unprocessedOpenedNotifis = [NSMutableArray new]; + for (OSNotificationClickEvent* event in [self getUnprocessedClickEvents]) { + [self fireClickListenersForEvent:event]; + } + _unprocessedClickEvents = [NSMutableArray new]; } + (BOOL)receiveRemoteNotification:(UIApplication*)application UserInfo:(NSDictionary*)userInfo completionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift index 743c3ff2d..73118e7cf 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift @@ -33,7 +33,7 @@ import OneSignalNotifications // MARK: - Push Subscription Specific @objc public protocol OSPushSubscriptionObserver { // TODO: weak reference? - @objc func onOSPushSubscriptionChanged(stateChanges: OSPushSubscriptionStateChanges) + @objc func onPushSubscriptionDidChange(state: OSPushSubscriptionChangedState) } @objc @@ -68,21 +68,21 @@ public class OSPushSubscriptionState: NSObject { } @objc -public class OSPushSubscriptionStateChanges: NSObject { - @objc public let to: OSPushSubscriptionState - @objc public let from: OSPushSubscriptionState +public class OSPushSubscriptionChangedState: NSObject { + @objc public let current: OSPushSubscriptionState + @objc public let previous: OSPushSubscriptionState @objc public override var description: String { - return "" + return "" } - init(to: OSPushSubscriptionState, from: OSPushSubscriptionState) { - self.to = to - self.from = from + init(current: OSPushSubscriptionState, previous: OSPushSubscriptionState) { + self.current = current + self.previous = previous } @objc public func jsonRepresentation() -> NSDictionary { - return ["from": from.jsonRepresentation(), "to": to.jsonRepresentation()] + return ["from": previous.jsonRepresentation(), "to": current.jsonRepresentation()] } } @@ -368,7 +368,7 @@ extension OSSubscriptionModel { return } - let stateChanges = OSPushSubscriptionStateChanges(to: newSubscriptionState, from: prevSubscriptionState) + let stateChanges = OSPushSubscriptionChangedState(current: newSubscriptionState, previous: prevSubscriptionState) // TODO: Don't fire observer until server is udated OneSignalLog.onesignalLog(.LL_VERBOSE, message: "firePushSubscriptionChanged from \(prevSubscriptionState.jsonRepresentation()) to \(newSubscriptionState.jsonRepresentation())") diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift index 2fed5a8b3..e2221f3d3 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift @@ -133,12 +133,12 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager { @objc public var requiresUserAuth = false // Push Subscription - private var _pushSubscriptionStateChangesObserver: OSObservable? - var pushSubscriptionStateChangesObserver: OSObservable { + private var _pushSubscriptionStateChangesObserver: OSObservable? + var pushSubscriptionStateChangesObserver: OSObservable { if let observer = _pushSubscriptionStateChangesObserver { return observer } - let pushSubscriptionStateChangesObserver = OSObservable(change: #selector(OSPushSubscriptionObserver.onOSPushSubscriptionChanged(stateChanges:))) + let pushSubscriptionStateChangesObserver = OSObservable(change: #selector(OSPushSubscriptionObserver.onPushSubscriptionDidChange(state:))) _pushSubscriptionStateChangesObserver = pushSubscriptionStateChangesObserver return pushSubscriptionStateChangesObserver diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageBridgeEvent.h b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageBridgeEvent.h index 915fa412d..eb4886ed5 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageBridgeEvent.h +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageBridgeEvent.h @@ -26,7 +26,7 @@ */ #import -#import "OSInAppMessageAction.h" +#import "OSInAppMessageClickResult.h" #import "OSInAppMessagePage.h" #import "OSInAppMessagingDefines.h" #import @@ -59,7 +59,7 @@ typedef NS_ENUM(NSUInteger, OSInAppMessageBridgeEventType) { @property (nonatomic) OSInAppMessageBridgeEventRenderingComplete *renderingComplete; @property (nonatomic) OSInAppMessageBridgeEventResize *resize; @property (nonatomic, nullable) OSInAppMessageBridgeEventPageChange *pageChange; -@property (strong, nonatomic, nullable) OSInAppMessageAction *userAction; +@property (strong, nonatomic, nullable) OSInAppMessageClickResult *userAction; @end NS_ASSUME_NONNULL_END diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageBridgeEvent.m b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageBridgeEvent.m index 394b5aed4..80cd7eb3c 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageBridgeEvent.m +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageBridgeEvent.m @@ -26,7 +26,7 @@ */ #import "OSInAppMessageBridgeEvent.h" -#import "OSInAppMessageAction.h" +#import "OSInAppMessageClickResult.h" #import "OneSignalHelper.h" @implementation OSInAppMessageBridgeEvent @@ -55,7 +55,7 @@ + (instancetype _Nullable)instanceWithJson:(NSDictionary *)json { // deserialize the action JSON if ([json[@"body"] isKindOfClass:[NSDictionary class]]) { - let action = [OSInAppMessageAction instanceWithJson:json[@"body"]]; + let action = [OSInAppMessageClickResult instanceWithJson:json[@"body"]]; if (!action) return nil; diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageClickEvent.h b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageClickEvent.h new file mode 100644 index 000000000..6a67c8fa2 --- /dev/null +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageClickEvent.h @@ -0,0 +1,38 @@ +/** + * Modified MIT License + * + * Copyright 2023 OneSignal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * 1. The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 2. All copies of substantial portions of the Software may only be used in connection + * with services provided by OneSignal. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#import +#import "OneSignalInAppMessaging.h" +#import "OSInAppMessageInternal.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface OSInAppMessageClickEvent () +- (instancetype _Nonnull)initWithInAppMessage:(OSInAppMessageInternal *)message clickResult:(OSInAppMessageClickResult *)result; +@end + +NS_ASSUME_NONNULL_END diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageClickEvent.m b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageClickEvent.m new file mode 100644 index 000000000..47c956aad --- /dev/null +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageClickEvent.m @@ -0,0 +1,50 @@ +/** + * Modified MIT License + * + * Copyright 2023 OneSignal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * 1. The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 2. All copies of substantial portions of the Software may only be used in connection + * with services provided by OneSignal. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#import "OSInAppMessageClickEvent.h" + +@implementation OSInAppMessageClickEvent + +- (instancetype)initWithInAppMessage:(OSInAppMessageInternal *)message clickResult:(OSInAppMessageClickResult *)result { + _message = message; + _result = result; + return self; +} + +- (NSDictionary *)jsonRepresentation { + let json = [NSMutableDictionary new]; + json[@"message"] = self.message; + json[@"result"] = [self.result jsonRepresentation]; + return json; +} + +- (NSString *)description { + return [NSString stringWithFormat:@"OSInAppMessageClickEvent message: %@ \nresult: %@", _message, [_result description]]; +} + +@end diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.h b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageClickResult.h similarity index 79% rename from iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.h rename to iOS_SDK/OneSignalSDK/Source/OSInAppMessageClickResult.h index 2b8a1fbb6..00efefc79 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.h +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageClickResult.h @@ -34,15 +34,7 @@ NS_ASSUME_NONNULL_BEGIN -typedef NS_ENUM(NSUInteger, OSInAppMessageActionUrlType) { - OSInAppMessageActionUrlTypeSafari, - - OSInAppMessageActionUrlTypeWebview, - - OSInAppMessageActionUrlTypeReplaceContent -}; - -@interface OSInAppMessageAction () +@interface OSInAppMessageClickResult () // The type of element that was clicked, button or image @property (strong, nonatomic, nonnull) NSString *clickType; @@ -50,11 +42,21 @@ typedef NS_ENUM(NSUInteger, OSInAppMessageActionUrlType) { // The unique identifier for this click @property (strong, nonatomic, nonnull) NSString *clickId; +//UUID for the page in an IAM Carousel +@property (strong, nonatomic, nullable) NSString *pageId; + + +// Whether or not the click action is first click on the IAM +@property (nonatomic) BOOL firstClick; + // The prompt action available @property (nonatomic, nullable) NSArray*> *promptActions; -// Determines where the URL is loaded, ie. app opens a webview -@property (nonatomic) OSInAppMessageActionUrlType urlActionType; +// The outcome to send for this action +@property (strong, nonatomic, nullable) NSArray *outcomes; + +// The tags to send for this action +@property (strong, nonatomic, nullable) OSInAppMessageTag *tags; @end diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.m b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageClickResult.m similarity index 77% rename from iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.m rename to iOS_SDK/OneSignalSDK/Source/OSInAppMessageClickResult.m index 2dda1052f..2c19349fd 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.m +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageClickResult.m @@ -26,11 +26,11 @@ */ #import "OneSignalHelper.h" -#import "OSInAppMessageAction.h" +#import "OSInAppMessageClickResult.h" #import "OSInAppMessagePushPrompt.h" #import "OSInAppMessageLocationPrompt.h" -@implementation OSInAppMessageAction +@implementation OSInAppMessageClickResult #define OS_URL_ACTION_TYPES @[@"browser", @"webview", @"replacement"] #define OS_IS_VALID_URL_ACTION(string) [OS_URL_ACTION_TYPES containsObject:string] @@ -49,7 +49,7 @@ + (instancetype _Nullable)instanceWithData:(NSData *)data { } + (instancetype _Nullable)instanceWithJson:(NSDictionary *)json { - OSInAppMessageAction *action = [OSInAppMessageAction new]; + OSInAppMessageClickResult *action = [OSInAppMessageClickResult new]; // on click goes here if ([json[@"click_type"] isKindOfClass:[NSString class]]) action.clickType = json[@"click_type"]; @@ -58,25 +58,25 @@ + (instancetype _Nullable)instanceWithJson:(NSDictionary *)json { action.clickId = json[@"id"]; if ([json[@"url"] isKindOfClass:[NSString class]]) - action.clickUrl = [NSURL URLWithString:json[@"url"]]; + action.url = json[@"url"]; if ([json[@"name"] isKindOfClass:[NSString class]]) - action.clickName = json[@"name"]; + action.actionId = json[@"name"]; if ([json[@"pageId"] isKindOfClass:[NSString class]]) action.pageId = json[@"pageId"]; if ([json[@"url_target"] isKindOfClass:[NSString class]] && OS_IS_VALID_URL_ACTION(json[@"url_target"])) - action.urlActionType = OS_URL_ACTION_TYPE_FROM_STRING(json[@"url_target"]); + action.urlTarget = OS_URL_ACTION_TYPE_FROM_STRING(json[@"url_target"]); else - action.urlActionType = OSInAppMessageActionUrlTypeWebview; + action.urlTarget = OSInAppMessageActionUrlTypeWebview; if ([json[@"close"] isKindOfClass:[NSNumber class]]) - action.closesMessage = [json[@"close"] boolValue]; + action.closingMessage = [json[@"close"] boolValue]; else - action.closesMessage = true; // Default behavior + action.closingMessage = true; // Default behavior - [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"OSInAppMessageAction %@", json]]; + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"OSInAppMessageClickResult %@", json]]; NSMutableArray *outcomes = [NSMutableArray new]; //TODO: when backend is ready check that key matches @@ -122,30 +122,18 @@ + (instancetype _Nullable)instancePreviewFromNotification:(OSNotification * _Non - (NSDictionary *)jsonRepresentation { let json = [NSMutableDictionary new]; - json[@"click_name"] = self.clickName; - json[@"first_click"] = @(self.firstClick); - json[@"closes_message"] = @(self.closesMessage); + json[@"actionId"] = self.actionId; + json[@"urlTarget"] = @(self.urlTarget); + json[@"closingMessage"] = @(self.closingMessage); - if (self.clickUrl) - json[@"click_url"] = self.clickUrl.absoluteString; - - if (self.outcomes && self.outcomes.count > 0) { - let *jsonOutcomes = [NSMutableArray new]; - for (OSInAppMessageOutcome *outcome in self.outcomes) { - [jsonOutcomes addObject:[outcome jsonRepresentation]]; - } - - json[@"outcomes"] = jsonOutcomes; - } - - if (self.tags) - json[@"tags"] = [self.tags jsonRepresentation]; + if (self.url) + json[@"url"] = self.url; return json; } - (NSString *)description { - return [NSString stringWithFormat:@"OSInAppMessageAction outcome: %@ \ntag: %@ promptAction: %@", _outcomes, _tags, [_promptActions description]]; + return [NSString stringWithFormat:@"OSInAppMessageClickResult actionId: %@ \nurl: %@ urlTarget: %@ closingMessage: %@", _actionId, _url, @(_urlTarget), @(_closingMessage)]; } @end diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageView.m b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageView.m index efe69aefe..27c19669f 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageView.m +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageView.m @@ -28,7 +28,7 @@ #import "OSInAppMessageView.h" #import "OneSignalHelper.h" #import -#import "OSInAppMessageAction.h" +#import "OSInAppMessageClickResult.h" #import "OneSignalViewHelper.h" @interface OSInAppMessageView () diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.h b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.h index 8f2a33998..d57b56a41 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.h +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.h @@ -29,14 +29,14 @@ #import #import "OSInAppMessageInternal.h" #import "OSInAppMessageView.h" -#import "OSInAppMessageAction.h" +#import "OSInAppMessageClickResult.h" #import NS_ASSUME_NONNULL_BEGIN @protocol OSInAppMessageViewControllerDelegate -- (void)messageViewDidSelectAction:(OSInAppMessageInternal *)message withAction:(OSInAppMessageAction *)action; +- (void)messageViewDidSelectAction:(OSInAppMessageInternal *)message withAction:(OSInAppMessageClickResult *)action; - (void)messageViewDidDisplayPage:(OSInAppMessageInternal *)message withPageId:(NSString *)pageId; - (void)messageViewControllerDidDisplay:(OSInAppMessageInternal *)message; - (void)messageViewControllerWillDismiss:(OSInAppMessageInternal *)message; diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.m b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.m index 047604c8b..47a82a468 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.m +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.m @@ -738,9 +738,9 @@ - (void)jsEventOccurredWithBody:(NSData *)body { case OSInAppMessageBridgeEventTypeActionTaken: { if (event.userAction.clickType) [self.delegate messageViewDidSelectAction:self.message withAction:event.userAction]; - if (event.userAction.urlActionType == OSInAppMessageActionUrlTypeReplaceContent) - [self.messageView loadReplacementURL:event.userAction.clickUrl]; - if (event.userAction.closesMessage) + if (event.userAction.urlTarget == OSInAppMessageActionUrlTypeReplaceContent) + [self.messageView loadReplacementURL:[NSURL URLWithString:event.userAction.url]]; + if (event.userAction.closingMessage) [self dismissCurrentInAppMessage]; break; } diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessagingRequests.h b/iOS_SDK/OneSignalSDK/Source/OSInAppMessagingRequests.h index 58d7ad061..881d76656 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessagingRequests.h +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessagingRequests.h @@ -7,7 +7,7 @@ // #import -#import "OSInAppMessageAction.h" +#import "OSInAppMessageClickResult.h" @interface OSRequestGetInAppMessages : OneSignalRequest + (instancetype _Nonnull)withSubscriptionId:(NSString * _Nonnull)subscriptionId; @@ -34,5 +34,5 @@ withPlayerId:(NSString * _Nonnull)playerId withMessageId:(NSString * _Nonnull)messageId forVariantId:(NSString * _Nonnull)variantId - withAction:(OSInAppMessageAction * _Nonnull)action; + withAction:(OSInAppMessageClickResult * _Nonnull)action; @end diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessagingRequests.m b/iOS_SDK/OneSignalSDK/Source/OSInAppMessagingRequests.m index 40444501d..3ab3154dc 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessagingRequests.m +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessagingRequests.m @@ -68,7 +68,7 @@ + (instancetype _Nonnull)withAppId:(NSString * _Nonnull)appId withPlayerId:(NSString * _Nonnull)playerId withMessageId:(NSString * _Nonnull)messageId forVariantId:(NSString * _Nonnull)variantId - withAction:(OSInAppMessageAction * _Nonnull)action { + withAction:(OSInAppMessageClickResult * _Nonnull)action { let request = [OSRequestInAppMessageClicked new]; request.parameters = @{ diff --git a/iOS_SDK/OneSignalSDK/Source/OSMessagingController.h b/iOS_SDK/OneSignalSDK/Source/OSMessagingController.h index 253fb26ff..d849cdbe3 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSMessagingController.h +++ b/iOS_SDK/OneSignalSDK/Source/OSMessagingController.h @@ -64,7 +64,8 @@ NS_ASSUME_NONNULL_BEGIN - (NSDictionary *)getTriggers; - (id)getTriggerValueForKey:(NSString *)key; -- (void)setInAppMessageClickHandler:(OSInAppMessageClickBlock)actionClickBlock; +- (void)addInAppMessageClickListener:(NSObject *_Nullable)listener; +- (void)removeInAppMessageClickListener:(NSObject *_Nullable)listener; - (void)setInAppMessageDelegate:(NSObject *_Nullable)delegate; - (void)removeInAppMessageDelegate:(NSObject *_Nullable)delegate; diff --git a/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m b/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m index e871d88e5..d1e623030 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m +++ b/iOS_SDK/OneSignalSDK/Source/OSMessagingController.m @@ -30,7 +30,8 @@ #import "UIApplication+OneSignal.h" // Previously imported via "OneSignalHelper.h" #import "NSDateFormatter+OneSignal.h" // Previously imported via "OneSignalHelper.h" #import -#import "OSInAppMessageAction.h" +#import "OSInAppMessageClickResult.h" +#import "OSInAppMessageClickEvent.h" #import "OSInAppMessageController.h" #import "OSInAppMessagePrompt.h" #import "OneSignalDialogController.h" @@ -93,8 +94,7 @@ @interface OSMessagingController () // Tracking for impessions so that an IAM is only tracked once and not several times if it is reshown @property (strong, nonatomic, nonnull) NSMutableSet *viewedPageIDs; -// Click action block to allow overridden behavior when clicking an IAM -@property (strong, nonatomic, nullable) OSInAppMessageClickBlock actionClickBlock; +@property (nonatomic) NSMutableArray *> *clickListeners; @property (weak, nonatomic, nullable) NSObject *inAppMessageDelegate; @@ -173,6 +173,7 @@ - (instancetype)init { defaultValue:[NSArray new]]; [self initializeTriggerController]; self.messageDisplayQueue = [NSMutableArray new]; + self.clickListeners = [NSMutableArray new]; let standardUserDefaults = OneSignalUserDefaults.initStandard; @@ -305,8 +306,12 @@ - (void)deleteOldRedisplayedInAppMessages { } } -- (void)setInAppMessageClickHandler:(OSInAppMessageClickBlock)actionClickBlock { - self.actionClickBlock = actionClickBlock; +- (void)addInAppMessageClickListener:(NSObject *_Nullable)listener { + [_clickListeners addObject:listener]; +} + +- (void)removeInAppMessageClickListener:(NSObject *_Nullable)listener { + [_clickListeners removeObject:listener]; } - (void)setInAppMessageDelegate:(NSObject *_Nullable)delegate { @@ -617,13 +622,13 @@ - (BOOL)shouldShowInAppMessage:(OSInAppMessageInternal *)message { return true; } -- (void)handleMessageActionWithURL:(OSInAppMessageAction *)action { - switch (action.urlActionType) { +- (void)handleMessageActionWithURL:(OSInAppMessageClickResult *)action { + switch (action.urlTarget) { case OSInAppMessageActionUrlTypeSafari: - [[UIApplication sharedApplication] openURL:action.clickUrl options:@{} completionHandler:^(BOOL success) {}]; + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:action.url] options:@{} completionHandler:^(BOOL success) {}]; break; case OSInAppMessageActionUrlTypeWebview: - [OneSignalHelper displayWebView:action.clickUrl]; + [OneSignalHelper displayWebView:[NSURL URLWithString:action.url]]; break; case OSInAppMessageActionUrlTypeReplaceContent: // This case is handled by the in-app message view controller. @@ -817,20 +822,26 @@ - (void)showAlertDialogMessage:(OSInAppMessageInternal *)inAppMessage }]; } -- (void)messageViewDidSelectAction:(OSInAppMessageInternal *)message withAction:(OSInAppMessageAction *)action { +- (void)messageViewDidSelectAction:(OSInAppMessageInternal *)message withAction:(OSInAppMessageClickResult *)action { // Assign firstClick BOOL based on message being clicked previously or not action.firstClick = [message takeActionAsUnique]; - if (action.clickUrl) + if (action.url) [self handleMessageActionWithURL:action]; if (action.promptActions && action.promptActions.count > 0) [self handlePromptActions:action.promptActions withMessage:message]; - - if (self.actionClickBlock) { - // Any outcome sent on this callback should count as DIRECT from this IAM + + if (_clickListeners.count > 0) { + // Any outcome sent on the listener's callback should count as DIRECT from this IAM [[OSSessionManager sharedSessionManager] onDirectInfluenceFromIAMClick:message.messageId]; - self.actionClickBlock(action); + } + + for (NSObject *listener in _clickListeners) { + if ([listener respondsToSelector:@selector(onClickInAppMessage:)]) { + OSInAppMessageClickEvent *event = [[OSInAppMessageClickEvent alloc] initWithInAppMessage:message clickResult:action]; + [listener onClickInAppMessage:event]; + } } if (message.isPreview) { @@ -862,7 +873,7 @@ - (void)messageWillDisplay:(nonnull OSInAppMessageInternal *)message { /* * Show the developer what will happen with a non IAM preview */ -- (void)processPreviewInAppMessage:(OSInAppMessageInternal *)message withAction:(OSInAppMessageAction *)action { +- (void)processPreviewInAppMessage:(OSInAppMessageInternal *)message withAction:(OSInAppMessageClickResult *)action { if (action.tags) [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"Tags detected inside of the action click payload, ignoring because action came from IAM preview\nTags: %@", action.tags.jsonRepresentation]]; @@ -881,7 +892,7 @@ - (BOOL)isClickAvailable:(OSInAppMessageInternal *)message withClickId:(NSString return ([message.displayStats isRedisplayEnabled] && [message isClickAvailable:clickId]) || ![_clickedClickIds containsObject:clickId]; } -- (void)sendClickRESTCall:(OSInAppMessageInternal *)message withAction:(OSInAppMessageAction *)action { +- (void)sendClickRESTCall:(OSInAppMessageInternal *)message withAction:(OSInAppMessageClickResult *)action { let clickId = action.clickId; // If the IAM clickId exists within the cached clickedClickIds return early so the click is not tracked // unless that click is from an IAM with redisplay @@ -916,7 +927,7 @@ - (void)sendClickRESTCall:(OSInAppMessageInternal *)message withAction:(OSInAppM }]; } -- (void)sendTagCallWithAction:(OSInAppMessageAction *)action { +- (void)sendTagCallWithAction:(OSInAppMessageClickResult *)action { if (action.tags) { OSInAppMessageTag *tag = action.tags; if (tag.tagsToAdd) @@ -1008,22 +1019,22 @@ - (void)onApplicationDidBecomeActive { } #pragma mark OSPushSubscriptionObserver Methods -- (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChanges * _Nonnull)stateChanges { +- (void)onPushSubscriptionDidChangeWithState:(OSPushSubscriptionChangedState * _Nonnull)state { // Don't pull IAMs if the new subscription ID is nil - if (stateChanges.to.id == nil) { - [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSMessagingController onOSPushSubscriptionChangedWithStateChanges: changed to nil subscription id"]; + if (state.current.id == nil) { + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSMessagingController onPushSubscriptionDidChange: changed to nil subscription id"]; return; } // Don't pull IAMs if the subscription ID has not changed - if (stateChanges.from.id != nil && - [stateChanges.to.id isEqualToString:stateChanges.from.id]) { - [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSMessagingController onOSPushSubscriptionChangedWithStateChanges: changed to the same subscription id"]; + if (state.previous.id != nil && + [state.current.id isEqualToString:state.previous.id]) { + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSMessagingController onPushSubscriptionDidChange: changed to the same subscription id"]; return; } // Pull new IAMs when the subscription id changes to a new valid subscription id - [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSMessagingController onOSPushSubscriptionChangedWithStateChanges: changed to new valid subscription id"]; - [self getInAppMessagesFromServer:stateChanges.to.id]; + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSMessagingController onPushSubscriptionDidChange: changed to new valid subscription id"]; + [self getInAppMessagesFromServer:state.current.id]; } - (void)dealloc { @@ -1039,14 +1050,15 @@ - (instancetype)init { self = [super init]; return self; } - (BOOL)isInAppMessagingPaused { return false; } - (void)setInAppMessagingPaused:(BOOL)pause {} - (void)getInAppMessagesFromServer {} -- (void)setInAppMessageClickHandler:(OSInAppMessageClickBlock)actionClickBlock {} +- (void)addInAppMessageClickListener:(NSObject *)listener {} +- (void)removeInAppMessageClickListener:(NSObject *)listener {} - (void)presentInAppMessage:(OSInAppMessageInternal *)message {} - (void)presentInAppPreviewMessage:(OSInAppMessageInternal *)message {} - (void)displayMessage:(OSInAppMessageInternal *)message {} - (void)messageViewImpressionRequest:(OSInAppMessageInternal *)message {} - (void)evaluateMessages {} - (BOOL)shouldShowInAppMessage:(OSInAppMessageInternal *)message { return false; } -- (void)handleMessageActionWithURL:(OSInAppMessageAction *)action {} +- (void)handleMessageActionWithURL:(OSInAppMessageClickResult *)action {} #pragma mark Trigger Methods - (void)addTriggers:(NSDictionary *)triggers {} - (void)removeTriggersForKeys:(NSArray *)keys {} @@ -1055,7 +1067,7 @@ - (void)clearTriggers {} - (id)getTriggerValueForKey:(NSString *)key { return 0; } #pragma mark OSInAppMessageViewControllerDelegate Methods - (void)messageViewControllerWasDismissed {} -- (void)messageViewDidSelectAction:(OSInAppMessageInternal *)message withAction:(OSInAppMessageAction *)action {} +- (void)messageViewDidSelectAction:(OSInAppMessageInternal *)message withAction:(OSInAppMessageClickResult *)action {} - (void)webViewContentFinishedLoading:(OSInAppMessageInternal *)message {} #pragma mark OSTriggerControllerDelegate Methods - (void)triggerConditionChanged {} diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignal.m b/iOS_SDK/OneSignalSDK/Source/OneSignal.m index fe0f1da9c..0624dd32e 100755 --- a/iOS_SDK/OneSignalSDK/Source/OneSignal.m +++ b/iOS_SDK/OneSignalSDK/Source/OneSignal.m @@ -69,7 +69,6 @@ #import "OneSignalDialogController.h" #import "OSMessagingController.h" -#import "OSInAppMessageAction.h" #import "OSInAppMessageInternal.h" #import "OneSignalInAppMessaging.h" diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignalInAppMessaging.h b/iOS_SDK/OneSignalSDK/Source/OneSignalInAppMessaging.h index 3f78a4a2d..8a6952618 100644 --- a/iOS_SDK/OneSignalSDK/Source/OneSignalInAppMessaging.h +++ b/iOS_SDK/OneSignalSDK/Source/OneSignalInAppMessaging.h @@ -49,39 +49,33 @@ @end -@interface OSInAppMessageAction : NSObject +typedef NS_ENUM(NSUInteger, OSInAppMessageActionUrlType) { + OSInAppMessageActionUrlTypeSafari, + + OSInAppMessageActionUrlTypeWebview, + + OSInAppMessageActionUrlTypeReplaceContent +}; + +@interface OSInAppMessageClickResult : NSObject // The action name attached to the IAM action -@property (strong, nonatomic, nullable) NSString *clickName; +@property (strong, nonatomic, nullable) NSString *actionId; // The URL (if any) that should be opened when the action occurs -@property (strong, nonatomic, nullable) NSURL *clickUrl; - -//UUID for the page in an IAM Carousel -@property (strong, nonatomic, nullable) NSString *pageId; - -// Whether or not the click action is first click on the IAM -@property (nonatomic) BOOL firstClick; +@property (strong, nonatomic, nullable) NSString *url; // Whether or not the click action dismisses the message -@property (nonatomic) BOOL closesMessage; - -// The outcome to send for this action -@property (strong, nonatomic, nullable) NSArray *outcomes; +@property (nonatomic) BOOL closingMessage; -// The tags to send for this action -@property (strong, nonatomic, nullable) OSInAppMessageTag *tags; +// Determines where the URL is loaded, ie. app opens a webview +@property (nonatomic) OSInAppMessageActionUrlType urlTarget; // Convert the class into a NSDictionary - (NSDictionary *_Nonnull)jsonRepresentation; @end -@protocol OSInAppMessageDelegate -@optional -- (void)handleMessageAction:(OSInAppMessageAction * _Nonnull)action NS_SWIFT_NAME(handleMessageAction(action:)); -@end - @interface OSInAppMessageWillDisplayEvent : NSObject @property (nonatomic, readonly, nonnull) OSInAppMessage *message; @end @@ -110,6 +104,18 @@ NS_SWIFT_NAME(onWillDismiss(event:)); NS_SWIFT_NAME(onDidDismiss(event:)); @end +@interface OSInAppMessageClickEvent : NSObject +@property (nonatomic, readonly, nonnull) OSInAppMessage *message; +@property (nonatomic, readonly, nonnull) OSInAppMessageClickResult *result; +// Convert the class into a NSDictionary +- (NSDictionary *_Nonnull)jsonRepresentation; +@end + +@protocol OSInAppMessageClickListener +- (void)onClickInAppMessage:(OSInAppMessageClickEvent *_Nonnull)event +NS_SWIFT_NAME(onClick(event:)); +@end + /** Public API for the InAppMessages namespace. */ @@ -124,8 +130,8 @@ NS_SWIFT_NAME(onDidDismiss(event:)); + (BOOL)paused NS_REFINED_FOR_SWIFT; + (void)paused:(BOOL)pause NS_REFINED_FOR_SWIFT; -typedef void (^OSInAppMessageClickBlock)(OSInAppMessageAction * _Nonnull action); -+ (void)setClickHandler:(OSInAppMessageClickBlock _Nullable)block; ++ (void)addClickListener:(NSObject *_Nullable)listener NS_REFINED_FOR_SWIFT; ++ (void)removeClickListener:(NSObject *_Nullable)listener NS_REFINED_FOR_SWIFT; + (void)addLifecycleListener:(NSObject *_Nullable)listener NS_REFINED_FOR_SWIFT; + (void)removeLifecycleListener:(NSObject *_Nullable)listener NS_REFINED_FOR_SWIFT; @end diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignalInAppMessaging.m b/iOS_SDK/OneSignalSDK/Source/OneSignalInAppMessaging.m index 65a9f0692..eeed2a0f7 100644 --- a/iOS_SDK/OneSignalSDK/Source/OneSignalInAppMessaging.m +++ b/iOS_SDK/OneSignalSDK/Source/OneSignalInAppMessaging.m @@ -39,9 +39,14 @@ + (void)start { [OSMessagingController start]; } -+ (void)setClickHandler:(OSInAppMessageClickBlock)block { - [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"In app message click handler set successfully"]; - [OSMessagingController.sharedInstance setInAppMessageClickHandler:block]; ++ (void)addClickListener:(NSObject *_Nullable)listener { + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"In app message click listener added successfully"]; + [OSMessagingController.sharedInstance addInAppMessageClickListener:listener]; +} + ++ (void)removeClickListener:(NSObject *_Nullable)listener { + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"In app message click listener removed successfully"]; + [OSMessagingController.sharedInstance removeInAppMessageClickListener:listener]; } + (void)addLifecycleListener:(NSObject *_Nullable)listener { diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignalLiveActivityController.m b/iOS_SDK/OneSignalSDK/Source/OneSignalLiveActivityController.m index ea775a0e4..d068ba405 100644 --- a/iOS_SDK/OneSignalSDK/Source/OneSignalLiveActivityController.m +++ b/iOS_SDK/OneSignalSDK/Source/OneSignalLiveActivityController.m @@ -86,8 +86,8 @@ + (void)initialize { [OneSignalUserManagerImpl.sharedInstance addObserver:shared]; } -- (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChanges * _Nonnull)stateChanges { - if(stateChanges.to.id){ +- (void)onPushSubscriptionDidChangeWithState:(OSPushSubscriptionChangedState * _Nonnull)state { + if(state.current.id){ subscriptionId = OneSignalUserManagerImpl.sharedInstance.pushSubscriptionId; [OneSignalLiveActivityController executePendingLiveActivityUpdates]; } diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignalSwiftInterface.swift b/iOS_SDK/OneSignalSDK/Source/OneSignalSwiftInterface.swift index 55a9179f6..7dfaf6981 100644 --- a/iOS_SDK/OneSignalSDK/Source/OneSignalSwiftInterface.swift +++ b/iOS_SDK/OneSignalSDK/Source/OneSignalSwiftInterface.swift @@ -84,6 +84,14 @@ public extension OSInAppMessages { static func removeLifecycleListener(_ listener: OSInAppMessageLifecycleListener) { __remove(listener) } + + static func addClickListener(_ listener: OSInAppMessageClickListener) { + __add(listener) + } + + static func removeClickListener(_ listener: OSInAppMessageClickListener) { + __remove(listener) + } } public extension OSSession { @@ -116,6 +124,14 @@ public extension OSNotifications { static func removePermissionObserver(_ observer: OSNotificationPermissionObserver) { return __remove(observer) } + + static func addClickListener(_ listener: OSNotificationClickListener) { + return __add(listener) + } + + static func removeClickListener(_ listener: OSNotificationClickListener) { + return __remove(listener) + } } public extension OSLocation {