*Please note that on 10/4/2017 "BKON Connect" became "Phy", so if you see any brand inconsistencies, we simply haven't finished our updates. Please be patient -- we'll get there!*
- Right click on any image or gif and select "Open Image in New Tab" to enlarge it or use the zoom feature in your browser or os.
- This tutorial and screenshots were created using Xcode 8.3.3(8E3004b) and Swift 3.0 so if you're using another version, some instructions will be slightly different but the Phy SDK will work.
Open your Xcode Project from where we left off in tutorial 1.2 or download it here:
In tutorial 1.2, we showed how to customize the Physical Web modal by changing the colors of the text, navigation bar, and beacon cell border.
In this section, we will show you how to use the Phy SDK to turn proximity sorting off and on for your Physical Web beacons in your PW modal view using the setDelayedReport() function.
When we left off, our project looked like this after the addition of our custom colors in the modal:
And when we run our app we should see our storyboard with our button.
Then when we tap our button, we launch the modal which discovers any area Physical Web beacons.
Understanding how sorting works in the SDK:
Let's say we wanted to use the Phy SDK to instruct our app to sort area beacons and put them in order based on which one is closer to us. Great! You've already done that because, by default, the SDK already sorts area Physical Web beacons based on proximity whenever a user initiates a scan. This can be done by pulling/swiping down in the PW modal view or by launching the modal view by pressing the button we created in our storyboard. However, the SDK takes ~2 seconds to look for, retrieve, and sort Physical Web beacons and some developers may want the option to forgo the ~2 second wait time in order to show users beacons the instance the SDK discovers them. This is where the Phy SDK method named setDelayedReport() comes in.
The setDelayedReport() method takes a boolean as a parameter and allows developers to toggle this sorting of area beacons on and off. As I said before, this boolean is set to true by default which tells the SDK to take the first ~2 seconds of every scan to discover area beacons and order based off of proximity to the device.
I have a few beacons here at my desk. The closest one to my iPhone is on and broadcasting our "Quick Start Guide" and the next closest one is broadcasting the "Physical Web GitHub" page. The app picks them up every time I initiate a scan and orders them correctly as shown below, always placing the "Quick Start Guide" beacon content at the top of the list followed by the "Physical Web GitHub" beacon content.
*The beacons should at least be a few feet apart in order for the SDK to be able to differentiate the change in distance.
Now, suppose our users are impatient atnd complaining about the speed at which beacons are returned, not that our users or anyone on he Phy Platform team would... but if they did we as developers could use the setDelayedReport() method to turn off sorting and show area beacons as soon as they're discovered. Let's see what including this code in our project looks like.
In the viewDidLoad() method where we instantiate our PhyEddystoneManager with our appID and set it as our bkonManager, we also now want to tell our bkonManager to not sort beacons when they are discovered and instead immediately display them to our users in our modal. To do this we need to include this line at the bottom of our viewDidLoad() method:
We can see the slight improvement in the speed of beacon discovery by our modal when conducting A/B testing. If you wanted to set your app to sort again, you could just set the boolean to true or omit setting the delayedReport altogether which leaves the default setting and your app will always sort your area Physical Web Beacons.
Take a look at the sorting speed vs the unsorted speed below:
Sorting area Physical Web Beacons
Not sorting area Physical Web Beacons:
In our next tutorial, we'll use the Phy SDK to mark PhyIDs (used for QR Codes, NFC Tags, and Physical Web Beaconss) as a favorite and take a look behind the scenes at our modal view. Feel free to comment below if you're having any trouble. Thank you!