ios - Updating WatchKit App With Beacon Ranging -


i working create swift-based ios app incorporates ibeacons provide data watchkit (os 1) app. app loads data json tableview based upon whether beacon clproximity set .near or .immediate. ios app, when launched, able detect beacons without issue, populate variable, , make available watchkit app. however, when watchkit app attempts request beacon data app using application:handlewatchkitextensionrequest when ios has not been launched first, object beacons come nil. assumption when app closed on phone, watchkit call open parent application not trigger beacon ranging code stored in appdelegate. moving beacon initialization code application:handlewatchkitextensionrequest not fix issue.

how 1 go constructing app (in general terms, know enough code don't need line line breakdown, though you're free if think others) where:

  1. the app user launches watch app check data nearby.
  2. the watch app requests list of near/immediate beacons ios app.
  3. the ios app returns list of either beacon major strings beacons fit criteria.
  4. optimally, ios app lets watch app know when list changes , watchkit app updates.

i have feeling part of solution lies in darwinnotification , registering observers, not things i've worked lot before, there enough examples on stackoverflow can implement them if case. guess real issue how gather beacon data when ios application hasn't been started yet.

moving code application:handlewatchkitextensionrequest partially solves problem ; main issue lies in beacon not ready (cllocationmanager asynchronous component) , takes time information need.

i working on similar fun project of mine - video player watch os1 (which not have video player functionality) , managed it. model of wk1 simple - request app, option reply in

  func application(application: uiapplication, handlewatchkitextensionrequest userinfo: [nsobject : anyobject]?, reply: (([nsobject : anyobject]!) -> void)!) 

now fun part , ended using don't have call reply() in method, can wait reply after event finishes. in case, asynchronously frames of video x sec buffer , send "yup, ready load them now" once video processing ended.

so in opinion following:

  • in watch app, request beacon data
  • in app, check if have beacon data
  • if have them, present them in wkinterfacetable or that
  • if don't, request beacon, store reply closure
  • once receive data beacon, call closure same way in (3)

there might 1 problem application terminated before desired response. in case, calling following should take care of that

uiapplication.sharedapplication().beginbackgroundtaskwithexpirationhandler({}) 

proper way how use background tasks explained detail here, providing link you.

also, don't forget can save data nsuserdefaults, or if use database, there. way, present results user right away , refresh them new results once fetch done, more optimization full solution.

if have additional questions or there problem solution, ask , figure out! :) luck!

edit:

after posted answer, stumbled upon this answer, provides need. think might little overcomplicated. anyway, posting here reference can have little more material work with.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -