Skip to content

Push

Introduction

StreetHawk's Push component lets you send push messages to your application. Depending on your application's current state, if your application in foreground, the push notification overlays on the current screen as a notification dialog with user to take action and for application in background, the SDK generates a notification in notification bar. Push modules also support custom dialog.

Pre-requisites

StreetHawkPush 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 StreetHawkPush Component

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

  • Check StreetHawk.IOS.Push.dll reference

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

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

  • Configure iOS push

Follow details steps to configure push notification.

  • Include Push module

Include StreetHawk component adding following statement:

using StreethawkIOS.Core;
using StreethawkIOS.Push;

Must call at least one function of Push module to make sure link to it. For very simple use case, just add this line:

public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
    //Simply call one function of Push module to make sure linking to it.
    SHPush.instance().isDefaultNotificationEnabled = true;

Send Your First Push Message


After the install is successfully registered with StreetHawk, you can send a test push message by clicking User search under Growth campaigns, click on your test install and select Send Notification Tab. Enter any title and message and press send button. You should see a test message (Simple push message) arriving on your device.

Supporting Custom Dialogs Themes

StreetHawk is capable to customize the confirm dialog of push notification, and response to the decision result

  • Create a class conform to ISHCustomiseHandler interface. Implement functions.
class MyHandler : ISHCustomiseHandler
    {
        public override void shRawJsonCallbackWithTitle (string title, string message, string json)
        {
            Console.WriteLine ("raw json title: " + title);
            Console.WriteLine ("raw json message: " + message);
            Console.WriteLine ("raw json content: " + json);
        }

        public override bool onReceive (PushDataForApplication pushData, ClickButtonHandler handler)
        {
            Console.WriteLine ("receive push data action: " + pushData.action.ToString());
            Console.WriteLine ("receive push data code: " + pushData.code.ToString());
            Console.WriteLine ("receive push data title: " + pushData.title);
            Console.WriteLine ("receive push data message: " + pushData.message);
            if (pushData.data != null) 
            {
                Console.WriteLine ("receive push data data: " + pushData.data.ToString ());
            }
            Console.WriteLine ("receive push data msg id: " + pushData.msgID.ToString());
            Console.WriteLine ("receive push data display without dialog: " + pushData.displayWithoutDialog.ToString());
            Console.WriteLine ("receive push data is foreground: " + pushData.isAppOnForeground.ToString());
            Console.WriteLine ("receive push data badge: " + pushData.badge.ToString());
            Console.WriteLine ("receive push data sound: " + pushData.sound);
            Console.WriteLine ("receive push data is slide: " + pushData.isInAppSlide.ToString());
            Console.WriteLine ("receive push data orientation: " + pushData.orientation.ToString());
            Console.WriteLine ("receive push data portion: " + pushData.portion.ToString());
            Console.WriteLine ("receive push data speed: " + pushData.speed.ToString());

//          if (pushData.action == SHAction.SHAction_OpenUrl) 
//          {
//              if (handler != null) 
//              {
//                  handler (SHResult.SHResult_Accept);
//              }
//              return true;
//          }

            return false;
        }

        public override void onReceiveResult (PushDataForApplication pushData, SHPushResult result)
        {
            Console.WriteLine ("receive result: " + result.ToString());
            Console.WriteLine ("receive result action: " + pushData.action.ToString());
            Console.WriteLine ("receive result code: " + pushData.code.ToString());
            Console.WriteLine ("receive result title: " + pushData.title);
            Console.WriteLine ("receive result message: " + pushData.message);
            if (pushData.data != null) 
            {
                Console.WriteLine ("receive result data: " + pushData.data.ToString ());
            }
            Console.WriteLine ("receive result msg id: " + pushData.msgID.ToString());
            Console.WriteLine ("receive result display without dialog: " + pushData.displayWithoutDialog.ToString());
            Console.WriteLine ("receive result is foreground: " + pushData.isAppOnForeground.ToString());
            Console.WriteLine ("receive result badge: " + pushData.badge.ToString());
            Console.WriteLine ("receive result sound: " + pushData.sound);
            Console.WriteLine ("receive result is slide: " + pushData.isInAppSlide.ToString());
            Console.WriteLine ("receive result orientation: " + pushData.orientation.ToString());
            Console.WriteLine ("receive result portion: " + pushData.portion.ToString());
            Console.WriteLine ("receive result speed: " + pushData.speed.ToString());
        }
    }
  • Set this handler class to StreetHawk.
MyHandler *handler = [[MyHandler alloc] init];
[StreetHawk shSetCustomiseHandler:handler];

Delay asking for Permission

By default StreetHawk library register push notification when call “streethawkinit” in “didFinishLaunchingWithOptions”. In case you may wish to delay asking the user for push notification permission, you can add the code be as shown below.

//optional to delay ask for permission
SHPush.instance().isDefaultNotificationEnabled = false;  //make streethawkinit not register for user notification, delay for later time.

//do SHApp.instance ().streethawkinit (); and other things.

SHPush.instance().isNotificationEnabled = true;  //later when ready to register for user notification, call this.

Handle none StreetHawk push payload

It's possible that another push server sends push to App, and it's not StreetHawk pre-defined code. To get noticed when this kind of push arrives, register:

SHPush.instance ().registerNonSHPushPayloadObserver = delegate(NSDictionary payload) {
                InvokeOnMainThread (() => {
                    UIAlertView alert = new UIAlertView ("None StreetHawk payload: ", payload.ToString(), null, "OK", null);
                    alert.Show ();
                });
            };

Add Interactive Pair Buttons

To add interactive pair buttons to App, use code sample:

InteractivePush pair1 = new InteractivePush("FacebookTwitter", "Facebook", "Twitter");
InteractivePush pair2 = new InteractivePush ("EmailPhone", "Email", "Phone");
SHPush.instance ().setInteractivePushBtnPairs (new InteractivePush [2] { pair1, pair2 });