Skip to content

Supporting Application Specific Dialogs (iOS)

StreetHawk SDK supports displaying of StreetHawk push messages in dialogs customised for your application by delivering push data to application using ISHCustomiseHandler. Below are the steps for handling application specific dialogs.

Step 1. Implement ISHCustomiseHandler

Implement ISHCustomiseHandler interface in your application.

@interface MyHandler : NSObject<ISHCustomiseHandler, UIActionSheetDelegate>

@property (nonatomic, copy) ClickButtonHandler callbackHandler;

@end

Step 2. Implement Custom dialog in - (BOOL)onReceive:(PushDataForApplication *)pushData clickButton:(ClickButtonHandler)handler

This function will receive push data from StreetHawk server bundled inside an object of type PushDataForApplication.

- (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)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
        }
    }
}

Step 3. Register ISHCustomiseHandler

Register object of class implementing ISHCustomiseHandler with StreetHawk using shSetCustomiseHandler API.

    MyHandler *handler = [[MyHandler alloc] init];
    [StreetHawk shSetCustomiseHandler:handler];