I am working to create a Swift-based iOS app that incorporates iBeacons to provide data to a WatchKit (OS 1) app. The app loads data from a JSON into a tableView based upon whether the beacon CLProximity
is set to .Near
or .Immediate
. The iOS app, when launched, is able to detect beacons without issue, populate a variable, and make it available to the WatchKit app. However, when the WatchKit app attempts to request the beacon data back from the app using application:handleWatchKitExtensionRequest
when the iOS has not been launched first, the object for the beacons come back as nil
. My assumption is that when the app is closed on the phone, the WatchKit call to open the parent application does NOT trigger beacon ranging code that is stored in the AppDelegate. Moving the beacon initialization code into the application:handleWatchKitExtensionRequest
does not fix the issue.
How would one go about constructing the app (in general terms, I know enough code that I don't necessarily need a line by line breakdown, though you're free to do so if you think it would help others) where:
- The app user launches the watch app to check for data nearby.
- The watch app requests a list of near/immediate beacons from the iOS app.
- The iOS app returns a list of either beacon Major strings for beacons that fit this criteria.
- Optimally, the iOS app lets the Watch App know when that list changes and the WatchKit app updates.
I have a feeling that part of my solution lies in DarwinNotification and with registering observers, which are not things i've worked with a lot before, but there are enough examples on StackOverflow that I can implement them if that is the case. I guess the real issue is how to gather that beacon data when the iOS application hasn't been started yet.