Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added jsonRepresentation method to OSInAppMessageAction class #704

Merged
merged 3 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};

Expand Down
14 changes: 14 additions & 0 deletions iOS_SDK/OneSignalSDK/Source/OSInAppMessageAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* THE SOFTWARE.
*/

#import "OneSignalHelper.h"
#import "OSInAppMessageAction.h"
#import "OSInAppMessagePushPrompt.h"
#import "OSInAppMessageLocationPrompt.h"
Expand Down Expand Up @@ -109,6 +110,19 @@ + (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;

return json;
}

- (NSString *)description {
return [NSString stringWithFormat:@"OSInAppMessageAction outcome: %@ \ntag: %@ promptAction: %@", _outcomes, _tags, [_promptActions description]];
}
Expand Down
11 changes: 7 additions & 4 deletions iOS_SDK/OneSignalSDK/Source/OneSignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,21 @@ typedef NS_ENUM(NSUInteger, OSNotificationDisplayType) {

@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;

// Convert the class into a NSDictionary
- (NSDictionary *_Nonnull)jsonRepresentation;

@end

@protocol OSInAppMessageDelegate <NSObject>
Expand Down