I just started learning beacons in MFP and have question concerning actionPayload for a trigger. Knowledge Center gives JSON example with
"actionPayload" : {"alert" : "Avail lowest interest rate of just 7.5% on home loans!"}
I'm trying to realize:
What are the actions available except of alert?
How could I define callback function for the trigger?
Thanks in advance!
If you use as-is the following function in iOSNativeiBeacons/iOSNativeiBeaconsLibrary/WLBeaconsLocationManager.m
, then beacon-trigger's actionPayload
can either be a local alert or a call to an adapter procedure. The details of adapter call are given next.
-(void) fireTriggerAction:(WLBeaconTrigger *)beaconTrigger forWLBeacon:(WLBeacon *)wlBeacon
{
NSString *branchName = [wlBeacon.customData objectForKey:@"branchName"];
NSString *alertMessage = [beaconTrigger.actionPayload objectForKey:@"alert"];
if(alertMessage != nil) {
alertMessage = [alertMessage stringByReplacingOccurrencesOfString:@"$branchName" withString:branchName];
NSString *alertTitle = [WLBeaconTrigger beaconTriggerTypeToString:beaconTrigger.triggerType];
[self sendLocalNotification:alertTitle withMessage:alertMessage];
} else {
NSString *adapterName = [beaconTrigger.actionPayload objectForKey:@"adapterName"];
NSString *procedureName = [beaconTrigger.actionPayload objectForKey:@"procedureName"];
NSString *userName = [self getUserName];
[self invokeAdapterProcedure:adapterName withProcedure:procedureName forUser:userName forBranch:branchName];
};
}
In a beacon-enabled banking app scenario, suppose we want to inform the bank branch manager when a high value customer enters the loan section of the branch, then following trigger can be registered and associated with the loan-section beacons.
beacon-trigger:
{
"triggerName" : "EnterLoanSection",
"triggerType" : "Enter",
"proximityState" : "Near",
"actionPayload" : {
"adapterName" : "BeaconsAdapter",
"procedureName" : "sendNotificationToBranchManager"
}
}
The actionPayload
in the trigger above specifies that the procedure sendNotificationToBranchManager
of adapter BeaconsAdapter
should be called upon entering the near proximity of associated beacons. That procedure will be defined in the adapter-files as below:
BeaconsAdapter.xml:
<procedure name="sendNotificationToBranchManager" />
BeaconsAdapter-impl.js:
function sendNotificationToBranchManager(userName, branchName) {
var notification = {};
notification.message = {};
notification.message.alert = "HNI customer, " + userName + ", is in loan-section of " + branchName + " branch.";
notification.settings = {};
WL.Server.sendMessage("ManagerApp", notification);
return {
result : "Notification sent"
};
}
Regarding "How could I define callback function for the trigger?", you could modify -(void) fireTriggerAction:(WLBeaconTrigger *)beaconTrigger forWLBeacon:(WLBeacon *)wlBeacon
in iOSNativeiBeacons/iOSNativeiBeaconsLibrary/WLBeaconsLocationManager.m