Skip to content

Feeds

Introduction

StreetHawk's Feed component is used for sending feeds to your application.

Pre-requisites

StreetHawkFeed component depends on StreetHawk's Analytics components. This document assumes that you have already integrated StreetHawkAnalytics component. if not then click here for detailed documentation on StreetHawkAnalytics components which describes steps to integrate Analytics component.

Integration Steps


  • Include StreetHawkFeed Component

1.In Xamarin Studio, double click on Components folder
2.Click on "Get More Components", and search for StreetHawk Feeds. Click Add to App
3.Once downloaded, click on Add to Project

  • Check StreetHawk.IOS.Feed.dll reference

Right click project->References->Edit References..., make sure StreetHawk.IOS.Core.dll and StreetHawk.IOS.Feed.dll are added to project.

For Unified projects, please add corresponding StreetHawk.IOS.Core-Unified.dll and StreetHawk.IOS.Feed-Unified.dll.

  • Include Feed module

Include StreetHawk component adding following statement:

using StreethawkIOS.Core;
using StreethawkIOS.Feed;
  • Callback handler when new feeds available

Register a callback handler which will be triggered when new feeds available.

            //streethawk handle new feeds.
            SHFeed.instance ().newFeedHandler = delegate {
                Console.WriteLine("New feeds available, do fetch from server.");    
            };
  • Fetch feeds

Fetch feeds from server. Offset means from which position to fetch, callback handler returns fetched array of feeds. There are four types of feed: news, offer, json and unknown.

                SHFeed.instance().feed(0, delegate (NSArray arrayFeeds, NSError error) {
                    InvokeOnMainThread ( () => {
                        if (error != null)
                        {
                            UIAlertView alert = new UIAlertView("Fetch feed meet error:", error.LocalizedDescription, null, "OK", null);
                            alert.Show();
                        }
                        else 
                        {
                            for (int i = 0; i < arrayFeeds.Count; i ++)
                            {
                                SHFeedObject feedObj = (SHFeedObject)arrayFeeds.GetItem<NSObject>(i);
                                SHFeed.instance().sendFeedAck(feedObj.feed_id);
                                SHFeed.instance().sendLogForFeed(feedObj.feed_id, SHFeedResult.SHResult_Accept);                                
                            }
                        }
                    });
                });
            };