StorylineDetail - mesosfer/Mesosfer-Cubeacon-iOS GitHub Wiki

Mesosfer provide a specialized bucket StorylineDetail that automatically handles much of the functionality required for storyline management.

Objects and Types

Here is some predefined StorylineDetail object :

  • event => NSString, define the event name of a storyline.
  • campaign => NSString, define the campaign type of a storyline.
  • beacons => NSArray, define array of beacon of a storyline.
  • showOn => NSArray, define array of key and value pairs within day name and boolean state of a storyline.
  • alertTitle => NSString, define the alert title of storyline, used for TEXT campaign.
  • alertMessage => NSString, define the alert message of storyline, used for TEXT campaign.
  • urlImageAndroid => NSString, define the url image for Android of storyline, used for IMAGE campaign.
  • urlImageiOS => NSString, define the url image for iOS of storyline, used for IMAGE campaign.
  • urlPage => NSString, define the url page of storyline, used for URL campaign.
  • urlVideo => NSString, define the url video of storyline, used for VIDEO campaign.

Saving Storyline Details

Let’s say you want to save the MFStorylineDetail described above to the Mesosfer Cloud with saveAsyncWithBlock: method:

// Storyline object
MFStoryline *storyline;

// create new Storyline Detail object
MFStorylineDetail *detail = [MFStorylineDetail storylineDetailWithStoryline:storyline];
// set campaign
detail.campaign = MFStorylineCampaignVideo;
// set event
detail.event = MFBeaconEventImmediate;
// set alert title
detail.alertTitle = @"App Notification";
// set alert message
detail.alertMessage = @"You have a notification.";
// set url video
detail.urlVideo = @"https://youtube.com/watch?v=mesosfer-video-campaign";

// set beacon list
NSArray<MFBeacon *> *beaconList;
detail.beacons = beaconList;
// set show on
MFShowDay *showOn = [[MFShowDay alloc] init];
[showOn enableAllDay];
detail.showOn = showOn;

// execute saving storyline detail
[detail saveAsyncWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
    // check if there is an exception happen
    if (error) {
        NSLog(@"Error saving storyline detail, cause: %@", error);
        return;
    }
    
    NSLog(@"Storyline detail successfully saved.");
}];

Retrieve Storyline Details

If you need to fetch a StorylineDetail with the latest data that is in the cloud, you can call the fetchAsyncWithBlock: method like so:

// create storyline detail from existing objecId
MFStorylineDetail *detail = [MFStorylineDetail storylineDetailWithObjectId:@"storylineDetailObjectId"];
// fetching the storyline detail data
[detail fetchAsyncWithBlock:^(id  _Nullable object, NSError * _Nullable error) {
    // check if there is an exception happen
    if (error) {
        NSLog(@"Error while fetching storyline detail, cause %@", error);
        return;
    }
    
    NSLog(@"Storyline detail fetched.");
}];

This will automatically update detail with the latest data from cloud.

Querying Storyline

There are many other ways to retrieve data with MFQuery. You can retrieve many data at once, put conditions on the data you wish to retrieve.

Basic Query

In many cases, there is a condition that need to specify which datas you want to retrieve. The MFQuery offers different ways to retrieve an array of MFStorylines. The general pattern is to create a MFQuery, put conditions on it, and then retrieve a NSArray of matching MFStorylineDetails using the findAsyncWithBlock: method. For example, to retrieve MFStorylines data with campaign VIDEO and event ENTER, use the whereEqualTo method to constrain the value for a key:

MFQuery *query = [MFStorylineDetail query];
[query whereKey:STORYLINE_DETAIL_KEY_CAMPAIGN equalTo:@(MFStorylineCampaignVideo)];
[query whereKey:STORYLINE_DETAIL_KEY_EVENT equalTo:@(MFBeaconEventEnter)];
[query findAsyncWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Error while finding storyline detail, cause %@", error);
        return;
    }
    
    NSLog(@"Found storyline detail: %lu", objects.count);
}];

Query Constraint

Refer to this link to learn more about query constraint.

Update Storyline

After getting the MFStorylineDetail data, you can update your data that stored in cloud using method saveAsyncWithBlock.

MFStorylineDetail *detail; // fetched storyline detail data
// update storyline detail data
detail.urlVideo = @"https://youtube.com/watch?v=cubeacon-video-campaign";
detail.event = MFBeaconEventNear;
// execute save data
[detail saveAsyncWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Error while updating storyline detail, cause %@", error);
        return;
    }
    
    NSLog(@"Storyline detail updated.");
}];

Delete Storyline Detail

To delete a MFStorylineDetail from the Mesosfer Cloud, use method deleteAsyncWithBlock: :

// the current Storyline object to delete
MFStorylineDetail *detail;
// execute delete storyline async
[detail deleteAsyncWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
    // check if there is an exception happen
    if (error) {
        NSLog(@"Error deleting storyline detail, cause: %@", error);
        return;
    }
    
    NSLog(@"Storyline detail deleted.");
}];
⚠️ **GitHub.com Fallback** ⚠️