Skip to content

Push

Introduction

Only available by Cocopods integration. It is push module of StreetHawk SDK. The module lets you send push messages to your application.

Prerequisite

  • Push modules requires XCode and Apple development portal configured properly. Click here to configure push messaging.

Integration Steps


  • Add pod to Application's Podfile

In pod file of your Application, add one line:

pod "streethawk/Push"
  • Install Pod

In the OS X command line terminal, enter the following command (making sure that you’re in the directory containing your project and Podfile).

First time to install StreetHawk framework:

pod install

Next to check and upgrade to latest StreetHawk framework:

pod update

You should see output similar to the following.

Analysing dependencies
Downloading dependencies
Installing streethawk/Core (1.7.0)
Installing streethawk/Push (1.7.0)
Generating Pods project
Integrating client project

This will automatically add StreetHawk/Core and StreetHawk/Push open source code into your pod project, and configure everything ready for use.

Note: there is a bug in Cocoapods, which may cause error "No such file or directory". Solution: delete Pods folder and Podfile.lock file, run "pod install" again.

  • Configure iOS push

Follow details steps to configure push notification.

  • 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.

@interface MyHandler : NSObject<ISHCustomiseHandler, UIActionSheetDelegate>

@property (nonatomic, copy) ClickButtonHandler callbackHandler;

@end

@implementation MyHandler

#pragma mark - override functions

- (BOOL)onReceive:(PushDataForApplication *)pushData clickButton:(ClickButtonHandler)handler
{
    self.callbackHandler = handler; //keep callback handler, will used in custom dialog event.
    if (pushData.action == SHAction_OpenUrl)
    {
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Show my own confirm dialog" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Go on", nil];
        [actionSheet showInView:[UIApplication sharedApplication].windows[0]];
        return YES; //only SHAction_OpenUrl use custom dialog, others keep StreetHawk's.
    }
    return NO; //others not affected
}

- (void)onReceiveResult:(PushDataForApplication *)pushData withResult:(SHResult)result
{
    if (pushData.isAppOnForeground) //UI action only happen when App in FG
    {
        if (pushData.action == SHAction_OpenUrl && result == SHResult_Decline)
        {
            [StreetHawk shFeedback:@[@"Not like the URL", @"The message is annoying", @"I am busy"] needInputDialog:NO needConfirmDialog:YES withTitle:@"Why decine the message?" withMessage:nil withPushData:nil];
        }
    }
}

#pragma mark - delegate handler

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex != actionSheet.cancelButtonIndex)
    {
        if (self.callbackHandler)
        {
            self.callbackHandler(SHResult_Accept); //notify streethawk to continue in positive way
        }
    }
    else
    {
        if (self.callbackHandler)
        {
            self.callbackHandler(SHResult_Decline); //notify streethawk to continue in negative way
        }
    }
}

@end

Swift code:

class MyHandler : NSObject, ISHCustomiseHandler
{
    func onReceive(_ pushData: PushDataForApplication!, clickButton handler: ClickButtonHandler!) -> Bool {

    }

    func onReceiveResult(_ pushData: PushDataForApplication!, with result: SHResult) {

    }
}
  • Set this handler class to StreetHawk.
MyHandler *handler = [[MyHandler alloc] init];
[StreetHawk shSetCustomiseHandler:handler];

Swift code:

SHApp.sharedInstance().shSetCustomiseHandler(MyHandler())
  • Delay asking for Permission

By default StreetHawk library register push notification when call “registerInstallForApp” 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.

StreetHawk.isDefaultNotificationEnabled = NO;  //make registerInstallForApp: not register for user notification, delay for later time.
//do [StreetHawk registerInstallForApp...] and other things.
StreetHawk.isNotificationEnabled = YES;  //later when ready to register for user notification, call this.

Swift code:

SHApp.sharedInstance().isDefaultNotificationEnabled = false  //make registerInstallForApp: not register for user notification, delay for later time.
//do SHApp.sharedInstance().registerInstallForApp(...) and other things.
SHApp.sharedInstance().isNotificationEnabled = true  //later when ready to register for user notification, call this.

Knowledge Base Articles

API document

Check here for API document.