Skip to content

Feeds

Introduction

StreetHawk Feed is used for sending feeds to your application.

Pre-requisites

The documents assume that you have downloaded and added the boiler-plate code described in the introduction document. You will require IStreetHawkFeeds.cs, StreetHawkFeeds.cs (iOS) and StreetHawkFeeds.cs (Android) in particular for StreetHawkGrowth component.

StreetHawk Feeds component depends on StreetHawk Analytics components. This document assumes that you have already integrated StreetHawk Analytics. If not then click here for detailed documentation which describes steps to integrate Analytics component.

Integration Steps

  • Add StreetHawk Feeds Component

Add StreetHawk Growth component in both iOS and Droid project as shown below:

  1. In iOS project, right click on component folder
  2. Click on "Get More Components" and search for StreetHawk Feeds. Click Add to App.
  3. Once downloaded, click on Add to Project.
  4. Repeat the above steps for adding the component in .Droid project of your application

  • Add platform specific code

    • Android
      Copy and paste the below code in AndroidManifest.xml located under properties folder of the .Droid project
      <?xml version="1.0" encoding="utf-8"?>
      <manifest >
      
          <application
              android:allowBackup="true"
              android:label="@string/app_name" >
              <receiver
                  android:name="com.streethawk.library.feeds.SHCoreModuleReceiver"
                  android:enabled="true"
                  android:exported="true" >
                  <intent-filter>
                      <action android:name="com.streethawk.intent.action.APP_STATUS_NOTIFICATION" />
                  </intent-filter>
              </receiver>
          </application>
      
      </manifest>
      
  • Callback handler when new feeds available
    Register a callback handler which will be triggered when new feeds available.

using StreetHawkCrossplatform;

protected override void OnStart()
{
    DependencyService.Get<IStreetHawkFeeds>().OnNewFeedAvailableCallback( delegate ()
    {
        DependencyService.Get<IStreetHawkFeeds>().ReadFeedData(0, delegate (System.Collections.Generic.List<SHFeedObject> arrayFeeds, string error)
            {
                Device.BeginInvokeOnMainThread(() =>
                    {
                        if (error != null)
                        {
                            MainPage.DisplayAlert("New feeds available but fetch meet error:", error, "OK");
                        }
                        else
                        {
                            string feeds = string.Empty;
                            for (int i = 0; i < arrayFeeds.Count; i++)
                            {
                                SHFeedObject feed = arrayFeeds[i];
                                feeds = string.Format("Title: {0}; Message: {1}; Content: {2}. \r\n{3}", feed.title, feed.message, feed.content, feeds);
                                DependencyService.Get<IStreetHawkFeeds>().SendFeedAck(feed.feed_id);
                                DependencyService.Get<IStreetHawkFeeds>().NotifyFeedResult(feed.feed_id, SHFeedResult.SHFeedResult_Accept);
                            }
                            MainPage.DisplayAlert(string.Format("New feeds available and fetch {0}:", arrayFeeds.Count), feeds, "OK");
                        }
                    });
            });
    });
  • Fetch feeds
    Fetch feeds from the 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.
using StreetHawkCrossplatform;

private void buttonFetchFeedClick(object sender, EventArgs e)
{
    DependencyService.Get<IStreetHawkFeeds>().ReadFeedData(0, delegate (System.Collections.Generic.List<SHFeedObject> arrayFeeds, string error)
        {
            Device.BeginInvokeOnMainThread(() =>
                {
                    if (error != null)
                    {
                        DisplayAlert("Fetch feeds meet error:", error, "OK");
                    }
                    else
                    {
                        string feeds = string.Empty;
                        for (int i = 0; i < arrayFeeds.Count; i++)
                        {
                            SHFeedObject feed = arrayFeeds[i];
                            feeds = string.Format("Title: {0}; Message: {1}; Content: {2}. \r\n{3}", feed.title, feed.message, feed.content, feeds);
                            DependencyService.Get<IStreetHawkFeeds>().SendFeedAck(feed.feed_id);
                            DependencyService.Get<IStreetHawkFeeds>().NotifyFeedResult(feed.feed_id, SHFeedResult.SHFeedResult_Accept);
                        }
                        DisplayAlert(string.Format("Fetch {0} feeds:", arrayFeeds.Count), feeds, "OK");
                    }
                });
        });
}