Search code examples
jsonios6passbookios6.1

How to add more than 10 locations for pass


I want to use many locations to show on lock screen. I tested already, only 10 locations is shown. Are there any way to show more than 10 locations ?


Solution

  • Rachel is correct in that Passbook will only recognise the first 10 locations included in pass.json. If there are any more than 10, then these will be ignored.

    The workaround that you link to, proposes the following:

    • You create a location enabled app
    • Whenever your app detects a significant location change, it signals your server, providing the pass serial number and the new location
    • Your server then selects the 10 closest locations, compiles a new pass and pushes it to the device

    Depending on how sophisticated you want to get in determining the most appropriate locations, it could be a bit of work. It also doesn't make for a great user experience since the location will eat battery and the constant updating of the pass will eat data.

    Three alternative approaches are:

    • Letting the user select the 10 most appropriate locations for them, or
    • Updating the locations whenever the pass is used. If the pass is scanned, then you can use the location of the scanning device to determine the 10 closest locations and push an updated pass, or
    • Adding a unique link on the back of the pass to a HTML5 page that grabs their current location with Javascript (see below), then initiates a push. E.g. To update you pass with the 10 nearest locations, click the link below http://www.yourservice.com/?passSerial=xxxx

    Sample location JS:

    <script>
    if(navigator.geolocation){
        navigator.geolocation.getCurrentPosition(success,fail);
    }
    
    function success(a) {            
        $("#long").val(a.coords.longitude).focus(); // focus required to force an update of the field value in webkit browsers
        $("#lat").val(a.coords.latitude).focus();
        // initiate ajax callback to push new pass and alert the user that it is on the way
    
    }
    function fail() {
        alert("You must give permission to provide your location, please refresh this page and try again");
    }
    </script>