2015-05-19 27 views
0

我剛剛在MFP中開始學習信標,並對觸發器的actionPayload有疑問。知識中心給出了信標觸發actionPayload可用的操作?

「actionPayload」 JSON例如:{ 「警告」: 「關於住房貸款的僅有7.5%,庫存狀況利率最低的!」}

我想實現:

  • 警報除外可用的操作有哪些?

  • 如何定義觸發器的回調函數?

在此先感謝!

回答

1

如果在iOSNativeiBeacons/iOSNativeiBeaconsLibrary/WLBeaconsLocationManager.m中原樣使用以下功能,則信標觸發器的actionPayload既可以是本地警報,也可以是對適配器過程的調用。下面給出適配器調用的細節。

-(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]; 
    }; 
} 

在信標使能應用銀行的情況下,假設我們要當一個高價值客戶進入分支的貸款部分,告知銀行分行經理,然後下面的觸發器可以註冊,並與該筆貸款─關聯部分信標。

信標觸發:

{ 
    "triggerName" : "EnterLoanSection", 
    "triggerType" : "Enter", 
    "proximityState" : "Near", 
    "actionPayload" : { 
     "adapterName" : "BeaconsAdapter", 
     "procedureName" : "sendNotificationToBranchManager" 
    } 
} 

在觸發器的actionPayload上述指定該過程適配器BeaconsAdaptersendNotificationToBranchManager應在進入相關聯的信標的附近接近被調用。該程序將在適配器文件中定義如下:

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" 
    }; 
} 

關於「我怎麼可以定義回調函數觸發器?「,你可以修改-(void) fireTriggerAction:(WLBeaconTrigger *)beaconTrigger forWLBeacon:(WLBeacon *)wlBeaconiOSNativeiBeacons/iOSNativeiBeaconsLibrary/WLBeaconsLocationManager.m

+1

非常感謝,溼婆!這就是我所尋找的。 – Timur