Showing the Feed Manually

The PuslateSDK also allows Developers to directly access the Pulsate Feed API to get the Pulsate Feed Models and build them in a custom way.

To get the Feed Models just call this method "-(void)getFeed:(nonnull NSString)page withListener:(nonnull FeedListener)listener". This method takes two arguments - "page" which specifies which page of the Feed do you want to get and "listener*" which is the listener to which we send the Feed Models and any errors if they occur. The models that are returned are - PULCard, PULTalk. Having all these models you can build a custom Feed.

PULPulsateManager* manager = [PULPulsateFactory getDefaultInstance];
[manager getFeed:@"1" withListener:^(NSArray *feed, NSError * _Nullable error) {
    if (feed.count > 0)
    {
       // Show Feed
    }
}];

Showing the Feed in a custom way also means that item clicks also need to be handled in a custom way. When handling on click events you must pass those clicks also to the PulsateSDK for it to be able to open the proper destination (deeplink, url, back of card, feed, reply) and also to send open event and custom events. To pass the clicks use the "-(void)handleFeedClick:(nonnull id)pulsateInboxItem" method.

PULPulsateManager* manager = [PULPulsateFactory getDefaultInstance];
[manager handleFeedClick:itemClicked];

Example:

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface CustomFeedViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
@property (strong,nonatomic) UITableView *table;
@property (strong,nonatomic) NSArray     *content;

@end

NS_ASSUME_NONNULL_END
#import "CustomFeedViewController.h"
#import <PULPulsate/PULPulsate.h>
#import <PULPulsate/PULCard.h>
#import <PULPulsate/PULTalk.h>
#import <PULPulsate/PULAdminHeaderBlock.h>
#import <PULPulsate/PULTextBlock.h>
#import <PULPulsate/PULImageBlock.h>
#import <PULPulsate/PULCallToActionBlock.h>
#include <math.h>

@interface CustomFeedViewController ()

@end

@implementation CustomFeedViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self cofigureTable];
    [self getTableContent];
}

-(void)cofigureTable
{
    self.table = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.view addSubview:self.table];
}

-(void)getTableContent
{
    PULPulsateManager* manager = [PULPulsateFactory getDefaultInstance];
    [manager getFeed:@"1" withListener:^(NSArray *feed, NSError * _Nullable error) {
        if (feed.count > 0)
        {
            self.content = feed;
            [self.table reloadData];
        }
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _content.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cellIdentifier";
    UITableViewCell *cell = [self.table dequeueReusableCellWithIdentifier:cellIdentifier];
    if(cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
        
    }
    
    id card = [_content objectAtIndex:indexPath.row];
    if ([card class] == [PULCard class]) {
        PULCard* pulCard = (PULCard*)card;
        cell.textLabel.text = @"Card";

        NSString* detail = @"Details: ";
        for (id viewBlock in [pulCard viewBlocks])
        {
            if ([viewBlock class] == [PULTextBlock class]) {
                PULTextBlock* textBlock = (PULTextBlock*)viewBlock;
                detail = [detail stringByAppendingString:textBlock.contentText];
            }
        }
        cell.detailTextLabel.text = detail;
    }
    else if ([card class] == [PULTalk class]) {
        PULTalk* pulTalk = (PULTalk*)card;
        cell.textLabel.text = @"Talk";

        NSString* detail = @"Details: ";
        detail = [detail stringByAppendingString:pulTalk.talkGUID];
        detail = [detail stringByAppendingString:pulTalk.adminName];
        detail = [detail stringByAppendingString:pulTalk.adminTitle];
        detail = [detail stringByAppendingString:pulTalk.adminAvatarURL];
        detail = [detail stringByAppendingString:pulTalk.userName];
        detail = [detail stringByAppendingString:pulTalk.userAvatarURL];
        cell.detailTextLabel.text = detail;
    }
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
    id card = [_content objectAtIndex:indexPath.row];
       if ([card isKindOfClass:[PULCard class]])
       {
           PULCard* cardData = card;
           PULPulsateManager* manager = [PULPulsateFactory getDefaultInstance];
           [manager handleFeedClick:cardData];
       }
       else if ([card class] == [PULTalk class]) {
           PULTalk* pulTalk = (PULTalk*)card;
           PULPulsateManager* manager = [PULPulsateFactory getDefaultInstance];
           [manager handleFeedClick:pulTalk];
       }
}
@end