diff --git a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m index 759c09798..7f697eca9 100644 --- a/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m +++ b/iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m @@ -56,11 +56,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( // Example block for IAM action click handler id inAppMessagingActionClickBlock = ^(OSInAppMessageAction *action) { - NSString *message = [NSString stringWithFormat:@"Click Action Occurred: clickName:%@ clickUrl:%@ firstClick:%i closesMessage:%i", - action.clickName, - action.clickUrl, - action.firstClick, - action.closesMessage]; + NSString *message = [NSString stringWithFormat:@"Click Action Occurred: %@", [action jsonRepresentation]]; [OneSignal onesignal_Log:ONE_S_LL_DEBUG message:message]; }; diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.h b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.h index fa632eb2a..337229630 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.h +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.h @@ -50,12 +50,6 @@ typedef NS_ENUM(NSUInteger, OSInAppMessageActionUrlType) { // The unique identifier for this click @property (strong, nonatomic, nonnull) NSString *clickId; -// 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; - // The prompt action available @property (nonatomic, nullable) NSArray*> *promptActions; diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.m b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.m index d4cad19ae..2bd1ec98b 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.m +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.m @@ -25,6 +25,7 @@ * THE SOFTWARE. */ +#import "OneSignalHelper.h" #import "OSInAppMessageAction.h" #import "OSInAppMessagePushPrompt.h" #import "OSInAppMessageLocationPrompt.h" @@ -109,6 +110,31 @@ + (instancetype)instanceWithJson:(NSDictionary *)json { return action; } +- (NSDictionary *)jsonRepresentation { + let json = [NSMutableDictionary new]; + + json[@"click_name"] = self.clickName; + json[@"first_click"] = @(self.firstClick); + json[@"closes_message"] = @(self.closesMessage); + + 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]; + + return json; +} + - (NSString *)description { return [NSString stringWithFormat:@"OSInAppMessageAction outcome: %@ \ntag: %@ promptAction: %@", _outcomes, _tags, [_promptActions description]]; } diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageOutcome.h b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageOutcome.h index a9d4d3670..73a585765 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageOutcome.h +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageOutcome.h @@ -32,11 +32,7 @@ #import "OSJSONHandling.h" #import "OneSignal.h" -@interface OSInAppMessageOutcome : NSObject - -@property (strong, nonatomic, nonnull) NSString *name; -@property (strong, nonatomic, nonnull) NSNumber *weight; -@property (nonatomic) BOOL unique; +@interface OSInAppMessageOutcome () @end diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageOutcome.m b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageOutcome.m index 94b71172c..4a6066e83 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageOutcome.m +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageOutcome.m @@ -25,6 +25,7 @@ * THE SOFTWARE. */ +#import "OneSignalHelper.h" #import "OSInAppMessageOutcome.h" @implementation OSInAppMessageOutcome @@ -65,6 +66,16 @@ + (instancetype _Nullable)instancePreviewFromPayload:(OSNotificationPayload * _N return nil; } +- (NSDictionary *)jsonRepresentation { + let json = [NSMutableDictionary new]; + + json[@"name"] = self.name; + json[@"weight"] = self.weight; + json[@"unique"] = @(self.unique); + + return json; +} + - (NSString *)description { return [NSString stringWithFormat:@"OSInAppMessageOutcome name: %@ weight: %@ unique: %s\n", _name, _weight, _unique ? "YES" : "NO"]; } diff --git a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageTag.h b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageTag.h index ca08a65f9..6b6366074 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSInAppMessageTag.h +++ b/iOS_SDK/OneSignalSDK/Source/OSInAppMessageTag.h @@ -32,10 +32,7 @@ #import "OSJSONHandling.h" #import "OneSignal.h" -@interface OSInAppMessageTag : NSObject - -@property (strong, nonatomic, nullable) NSDictionary *tagsToAdd; -@property (strong, nonatomic, nullable) NSArray *tagsToRemove; +@interface OSInAppMessageTag () @end diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignal.h b/iOS_SDK/OneSignalSDK/Source/OneSignal.h index a11b46d6d..8bed5da8a 100755 --- a/iOS_SDK/OneSignalSDK/Source/OneSignal.h +++ b/iOS_SDK/OneSignalSDK/Source/OneSignal.h @@ -189,20 +189,50 @@ typedef NS_ENUM(NSUInteger, OSNotificationDisplayType) { @end; +@interface OSInAppMessageOutcome : NSObject + +@property (strong, nonatomic, nonnull) NSString *name; +@property (strong, nonatomic, nonnull) NSNumber *weight; +@property (nonatomic) BOOL unique; + +// Convert the class into a NSDictionary +- (NSDictionary *_Nonnull)jsonRepresentation; + +@end + +@interface OSInAppMessageTag : NSObject + +@property (strong, nonatomic, nullable) NSDictionary *tagsToAdd; +@property (strong, nonatomic, nullable) NSArray *tagsToRemove; + +// Convert the class into a NSDictionary +- (NSDictionary *_Nonnull)jsonRepresentation; + +@end + @interface OSInAppMessageAction : NSObject -/* The action name attached to the IAM action */ +// The action name attached to the IAM action @property (strong, nonatomic, nullable) NSString *clickName; -/* The URL (if any) that should be opened when the action occurs */ +// The URL (if any) that should be opened when the action occurs @property (strong, nonatomic, nullable) NSURL *clickUrl; -/* Whether or not the click action is first click on the IAM */ +// Whether or not the click action is first click on the IAM @property (nonatomic) BOOL firstClick; -/* Whether or not the click action dismisses the message */ +// 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; + +// The tags to send for this action +@property (strong, nonatomic, nullable) OSInAppMessageTag *tags; + +// Convert the class into a NSDictionary +- (NSDictionary *_Nonnull)jsonRepresentation; + @end @protocol OSInAppMessageDelegate diff --git a/iOS_SDK/OneSignalSDK/UnitTests/InAppMessagingIntegrationTests.m b/iOS_SDK/OneSignalSDK/UnitTests/InAppMessagingIntegrationTests.m index 1c0423763..1df4ab877 100644 --- a/iOS_SDK/OneSignalSDK/UnitTests/InAppMessagingIntegrationTests.m +++ b/iOS_SDK/OneSignalSDK/UnitTests/InAppMessagingIntegrationTests.m @@ -1123,7 +1123,7 @@ - (void)testIAMClickedLaunchesUniqueOutcomeAPIV2Request { XCTAssertFalse(OneSignalClientOverrider.lastHTTPRequestType); } -- (void)testIAMClickedLaunchesTagSendPIRequest { +- (void)testIAMClickedLaunchesTagSendAPIRequest { let message = [OSInAppMessageTestHelper testMessageJsonWithTriggerPropertyName:OS_DYNAMIC_TRIGGER_KIND_SESSION_TIME withId:@"test_id1" withOperator:OSTriggerOperatorTypeLessThan withValue:@10.0]; let registrationResponse = [OSInAppMessageTestHelper testRegistrationJsonWithMessages:@[message]];