- 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 PhySdk 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 PW 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 PhySdk 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 PhySdk 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 PhySdk 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 and complaining about the speed at which beacons are returned, not that our users or anyone on the BKON 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 PW beacons
Not sorting area PW beacons:
In our next tutorial, we'll use the PhySdk to mark TouchPoints (i.e. PW beacons) 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 and thanks!