Custom Actions

How to use custom actions

When to use

At present there is a local notification action that can be setup and configured via the CMS with no code having to be written inside your app, it just works, however chances are that you want to perform some very specific actions based on whether someone crosses a geofence or comes into range of a beacon and this is were custom actions come into play.

🚧

CMS Setup

This guide already expects that you have setup the action in the CMS and configured, if this is not the case please visit http://proxitee-cms.readme.io which covers setting up actions in the CMS

Creating

A custom action should be a class that implements the PXTAction protocol, this protocol has a single method that must be implemented -(void)execute:(NSDictionary *)data;

In this example we have a custom action that determines if a person is inside a room using near proximity of a particular beacon a global boolean is then set.

#import "PXTAction.h"
#import "Room.h"  

@interface InsideRoomAction :  NSObject<PXTAction>
@end

#import "InsideRoomAction.h"
  
@implementation InsideRoomAction

-(void)execute:(NSDictionary *)data {
 		[Room shared].isInside = true;
}
  
@end

πŸ“˜

Data Dictionary Parameter

The data dictionary is the JSON object that is configured via the CMS serialized into a dictionary, this is where you can set values that are specific to your domain and the action you want to take place.

Registering

In order to use custom actions you use the exposed [PXTProxitee shared].actions object this has an interface to allow registering/unregistering custom actions.

Now we will register our InsideRoomAction custom action so that it will be executed based on the setup in the CMS.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
		[[PXTProxitee shared].actions register:@"insideroom" action:[[RoomAction alloc] init]];
}

Now that we have the action registered we can have full control over how we want it to be executed, in the example above were using the proximity of a particular beacon however there's no reason you couldn't have it be triggered by crossing into a geofence boundary.