Skip to main content

Overview

RadarInAppMessage is a data model class that represents an in-app message delivered by the Radar SDK. It contains structured content including title, body text, optional button, optional image, and custom metadata. The message supports full customization of colors, text, and interactive elements like deep links.

Properties

title
RadarInAppMessage.Text
required
The title text and color configuration for the message.
body
RadarInAppMessage.Text
required
The body text and color configuration for the message.
button
RadarInAppMessage.Button
Optional button configuration with text, colors, and deep link.
image
RadarInAppMessage.Image
Optional image configuration with name and URL.
metadata
[String: Sendable]
required
Custom metadata dictionary associated with the message.

Nested Types

RadarInAppMessage.Text

Represents text content with styling.
text
String
required
The text content to display.
color
UIColor
required
The color of the text.

RadarInAppMessage.Button

Represents an interactive button with optional deep link.
text
String
required
The button text to display.
color
UIColor
required
The text color of the button.
backgroundColor
UIColor
required
The background color of the button.
Optional deep link URL to open when the button is tapped.

RadarInAppMessage.Image

Represents an image to display in the message.
name
String
required
The name identifier for the image.
url
String
required
The URL where the image can be fetched.

Initializer

init(title:body:button:image:metadata:)

Creates a new in-app message with the specified components.
public init(
    title: Text,
    body: Text,
    button: Button?,
    image: Image?,
    metadata: [String: Sendable]
)
title
RadarInAppMessage.Text
required
The title text and color configuration.
body
RadarInAppMessage.Text
required
The body text and color configuration.
button
RadarInAppMessage.Button
Optional button configuration.
image
RadarInAppMessage.Image
Optional image configuration.
metadata
[String: Sendable]
required
Custom metadata dictionary.

Class Methods

fromDictionary(_:)

Creates an in-app message from a dictionary representation.
public static func fromDictionary(_ dict: [String: Any]) -> RadarInAppMessage?
+ (RadarInAppMessage * _Nullable)fromDictionary:(NSDictionary<NSString *, id> * _Nonnull)dict;
dict
[String: Any]
required
Dictionary containing the message data. Must include “title” and “body” keys at minimum.
Returns: A RadarInAppMessage instance if the dictionary contains valid data, or nil if required fields are missing.

fromArray(_:)

Creates an array of in-app messages from an array representation.
public static func fromArray(_ array: Any) -> [RadarInAppMessage]
+ (NSArray<RadarInAppMessage *> * _Nonnull)fromArray:(id _Nonnull)array;
array
Any
required
Array of dictionaries, each representing an in-app message.
Returns: An array of RadarInAppMessage instances. Invalid entries are filtered out.

Instance Methods

toDictionary()

Converts the in-app message to a dictionary representation.
public func toDictionary() -> [String: Any]
- (NSDictionary<NSString *, id> * _Nonnull)toDictionary;
Returns: A dictionary containing all message properties in a serializable format.

Example Usage

// Create a message programmatically
let title = RadarInAppMessage.Text(
    text: "Welcome!",
    color: .black
)

let body = RadarInAppMessage.Text(
    text: "Thank you for visiting our store.",
    color: .darkGray
)

let button = RadarInAppMessage.Button(
    text: "Learn More",
    color: .white,
    backgroundColor: .blue,
    deepLink: "myapp://promo"
)

let message = RadarInAppMessage(
    title: title,
    body: body,
    button: button,
    image: nil,
    metadata: ["campaign": "spring_sale"]
)

// Convert to dictionary for serialization
let dict = message.toDictionary()

// Parse from dictionary
if let parsedMessage = RadarInAppMessage.fromDictionary(dict) {
    print("Message title: \(parsedMessage.title.text)")
}
// Parse from dictionary
NSDictionary *messageDict = @{
    @"title": @{@"text": @"Welcome!", @"color": @"#000000"},
    @"body": @{@"text": @"Thank you for visiting.", @"color": @"#666666"},
    @"metadata": @{}
};

RadarInAppMessage *message = [RadarInAppMessage fromDictionary:messageDict];

See Also