Last modified March 9, 2022 by Shelly Wolfe

Swrve Message Center API

The Swrve Message Center is an API for campaigns that have been downloaded from Swrve and are intended to be accessible in a way where the app user is in control of the message lifecycle. This guide describes how the Message Center API is presented for iOS, Android and Unity.

Accessing the API

iOS

Once the Swrve instance is created in the AppDelegate as per the iOS Integration guide, retrieve a list all of the campaigns that the user qualifies for, and that are currently available, via NSArray* campaigns:

NSArray* campaigns = [[SwrveSDK messaging] messageCenterCampaigns];

The array contains a collection of SwrveBaseCampaign objects. Each of these is an entry in the app’s message center.

Android

SwrveSDK.createInstance(this, <app_id>, "<api_key>");

The shared instance contains methods to list all of the campaigns that this user qualifies for, and that are available right now:

List<SwrveBaseCampaign> campaigns = SwrveSDK.getMessageCenterCampaigns();

The list contains a collection of SwrveBaseCampaign objects. Each of these is an entry in the app’s message center.

Unity

The Swrve shared instance object contains a reference that you can use to list all of the campaigns that this user qualifies for, and that are available right now:

List<SwrveBaseCampaign> campaigns = SwrveComponent.Instance.SDK.GetMessageCenterCampaigns();

The array contains a collection of SwrveBaseCampaign objects. Each of these is an entry in the app’s message center.

Web

The Swrve shared instance object contains a reference that you can use to list all of the campaigns that this user qualifies for, and that are available right now:

var campaigns = SwrveSDK.getMessageCenterCampaigns();

The array contains a collection of ISwrveBaseCampaign objects. Each of these is an entry in the app’s message center.

To get the subject line of the campaign to display in the message center UI, use the following:

iOS

SwrveBaseCampaign *item = (SwrveBaseCampaign*)[campaigns objectAtIndex:0];
NSString* subject = item.subject;

Android

SwrveBaseCampaign item = campaigns.get(0);
String subject = item.getSubject();

Unity

SwrveBaseCampaign item = campaigns[0];
string subject = item.Subject;

Web

var item = campaigns[0];
var subject = item.subject;

To retrieve the status associated with each message center entry, use the following:

iOS

SwrveCampaignStatus status = item.state.status;

Possible values are:

Value Description
SWRVE_CAMPAIGN_STATUS_UNSEEN  = 0x1 Campaign hasn’t been seen by the user.
SWRVE_CAMPAIGN_STATUS_SEEN    = 0x2 Campaign has been seen at least once by the user.
SWRVE_CAMPAIGN_STATUS_DELETED = 0x3 Campaign has been deleted and won’t appear again in the inbox.

Android

SwrveCampaignState.Status status = item.getStatus();

Possible values are:

Value Description
SwrveCampaignState.Status.Unseen Campaign hasn’t been seen by the user.
SwrveCampaignState.Status.Seen Campaign has been seen at least once by the user.
SwrveCampaignState.Status.Deleted Campaign has been deleted and won’t appear again in the inbox.

Unity

SwrveCampaignState.Status status = item.Status;

Possible values are:

VALUE DESCRIPTION
SwrveCampaignState.Status.Unseen Campaign hasn’t been seen by the user.
SwrveCampaignState.Status.Seen Campaign has been seen at least once by the user.
SwrveCampaignState.Status.Deleted Campaign has been deleted and won’t appear again in the inbox.

 

Web

var status = item.status;

Possible values are:

VALUE DESCRIPTION
“unseen” Campaign hasn’t been seen by the user.
“seen” Campaign has been seen at least once by the user.

The SDK is responsible for rendering and reacting to the conversation, so this capability is provided by a single API call:

iOS

[[SwrveSDK messaging] showMessageCenterCampaign:item];

Android

SwrveSDK.showMessageCenterCampaign(item);

Unity

SwrveComponent.Instance.SDK.ShowMessageCenterCampaign(item);

Web

SwrveSDK.showMessageCenterCampaign(item);

Finally, to remove the campaign from visibility so it doesn’t appear in the message center again, use the following:

iOS

[[SwrveSDK messaging] removeMessageCenterCampaign:item];

Android

SwrveSDK.removeMessageCenterCampaign(item);

Unity

SwrveComponent.Instance.SDK.RemoveMessageCenterCampaign(item);

General use case

iOS

Use the NSArray* that the [[Swrve messaging] messageCenterCampaigns] call returns as a data provider to a table view, or custom view, for presentation in the app proper.

Android

Use the list that the SwrveSDK.getMessageCenterCampaigns() call returns as the source of an ArrayAdapter<SwrveBaseCampaign> used in a ListView, or custom view, for presentation in the app proper.

Unity

Use the list that the SDK returns to populate a ListLayout inside a Canvas and ScrollRect to display the items.

When the app user selects a campaign in the message center view, the app should call the showMessageCenterCampaign API call to present it to the user.

When the user deletes the entry in the message center view, then the app should call removeMessageCenterCampaign for the selected campaign.