Searching for an example of a proper iBeacon implementation for iOS 17

Hello,

I'm looking for an end-to-end example project that shows a correct implementation for the new iBeacon CoreLocation APIs in iOS 17.0 (CLMonitor, etc.). Ideally the example would cover background waking as that is the area in which I am facing the largest challenges.

Perhaps there's an Open Source project or an official Apple example?

Thanks for pointing me in the right direction.

Jeremy

Accepted Reply

The only official Apple example for using CLMonitor is at https://developer.apple.com/documentation/corelocation/monitoring_location_changes_with_core_location It does not demonstrate and end to end solution for iBeacons but will show the correct use of CLMonitor.

If you are able to use CLMonitor with beacons and they are working but not always, the cause of the issue is almost always due to the beacon devices not being fully compliant with the specifications. You may want to first check that they are, before struggling with your code.

If you can switch your BeaconIdentityCondition with a CircularGeographicCondition and see that the background wake works, then the issue would very likely be due to the beacon devices.

  • I am doing the same test with the apple example app using an iPhone-iOS 17.4 as the beacon using the deprecrated methods described here.

    The results appear to be the same with no monitoring events being generated for the beacon condition.

    Is this a valid test?

    Are there updated beacon implementation guidelines beyond what is described here?

Add a Comment

Replies

The only official Apple example for using CLMonitor is at https://developer.apple.com/documentation/corelocation/monitoring_location_changes_with_core_location It does not demonstrate and end to end solution for iBeacons but will show the correct use of CLMonitor.

If you are able to use CLMonitor with beacons and they are working but not always, the cause of the issue is almost always due to the beacon devices not being fully compliant with the specifications. You may want to first check that they are, before struggling with your code.

If you can switch your BeaconIdentityCondition with a CircularGeographicCondition and see that the background wake works, then the issue would very likely be due to the beacon devices.

  • I am doing the same test with the apple example app using an iPhone-iOS 17.4 as the beacon using the deprecrated methods described here.

    The results appear to be the same with no monitoring events being generated for the beacon condition.

    Is this a valid test?

    Are there updated beacon implementation guidelines beyond what is described here?

Add a Comment

I have used that example to create with the following code:

import Foundation
import CoreLocation

let monitorName = "BeaconMonitor"
let testBeaconId = UUID(uuidString: "EDFA3FFA-D80A-4C23-9104-11B5B0B8E8F3")!

@MainActor
public class ObservableMonitorModel: ObservableObject {
    private let manager: CLLocationManager
    
    public var monitor: CLMonitor?
    
    init() {
        self.manager = CLLocationManager()
        self.manager.requestWhenInUseAuthorization()
        self.manager.requestAlwaysAuthorization()
    }
    
    func startMonitoringConditions() {
        Task {
            monitor = await CLMonitor(monitorName)
            await monitor!.add(getBeaconIdentityCondition(), identifier: "Beacon")
            
            for identifier in await monitor!.identifiers {
                guard let lastEvent = await monitor!.record(for: identifier)?.lastEvent else { continue }
                print(identifier, lastEvent.state)
            }
            
            for try await event in await monitor!.events {
                print("Event", event.identifier, event)
                
            }
        }
    }
    
}

func getBeaconIdentityCondition() -> CLMonitor.BeaconIdentityCondition {
    CLMonitor.BeaconIdentityCondition(uuid: testBeaconId)
}

Unfortunately, running this on my iPhone only prints "Beacon CLMonitoringState". I don't see anything from the for try await block starting with "Event".

Any ideas where I've gone wrong?

[@Gualtier Malde](https://developer.apple.com/forums/profile/Gualtier Malde) I managed to get the entry/exit for beacon region on >iOS 17.0 to <=iOS 17.1.2, but it doesn't work at all on latest iOS version 17.3.1. I have tried with new addition in iOS 17.2, assuming unmonitored as well but still no result.

I'm using the sample code provided by apple, https://developer.apple.com/documentation/corelocation/monitoring_location_changes_with_core_location.

Please guide.

Thanks Pawan Rai