Reputation: 165
How's everyone doing with iBeacons on iOS 10.0.2 so far? I hope better than me! :-)
Update: Hardware used for testing was two iPhones. The iPhone 5S(A1533) and the iPhone 7(A1778)
A swift 2.x version of the code below could be used on an iPhone to advertise a simple iBeacon on iOS versions 9.x; today, the same code - updated for swift 3 and running on iOS 10.0.2 - doesn't appear to advertise at all.
I've cut code down to a very simple helper class and a viewcontroller that I think should adequately demonstrate the problem. Note that the storyboard has just one button connected to start/stop iBeacon advertising.
I've run the app on an iPhone 5 and an iPhone 7 with iOS 10.0.2. To test I created a custom scanner (sniffing for the specific proximity UUID,) and when that didn't work I tried more generic iBeacon detecting apps, like Estimote and LightBlue.
Sigh - nothing sees the iBeacon.
Thoughts? The developer forums at Apple mention problems reported with iBeacons in 10.x, but none as simple as this as far as I can tell.
Thanks a bunch...
- - - iBeaconConfiguration.swift - - - - - -
import Foundation
class iBeaconConfiguration
{
static let uuid = UUID(uuidString: "F34A1A1F-500F-48FB-AFAA-9584D641D7B1")!
private init() {}
}
- - - ViewController.swift - - - - - -
import UIKit
import CoreLocation
import CoreBluetooth
class ViewController: UIViewController, CBPeripheralManagerDelegate
{
@IBOutlet weak var btnAction: UIButton!
let UUID: UUID = iBeaconConfiguration.uuid
var beaconRegion: CLBeaconRegion!
var dataDictionary = NSDictionary()
var bluetoothPeripheralManager: CBPeripheralManager!
var isBroadcasting = false
override func viewDidLoad() {
super.viewDidLoad()
bluetoothPeripheralManager = CBPeripheralManager(delegate: self, queue: nil, options: nil)
}
@IBAction func switchBroadcastingState(_ sender: AnyObject)
{
if !isBroadcasting {
if bluetoothPeripheralManager.state == CBManagerState.poweredOn {
let major: CLBeaconMajorValue = 123
let minor: CLBeaconMinorValue = 456
beaconRegion = CLBeaconRegion(proximityUUID: UUID, major: major, minor: minor, identifier: "com.rdz.bcast")
dataDictionary = beaconRegion.peripheralData(withMeasuredPower: nil)
bluetoothPeripheralManager.startAdvertising(dataDictionary as? [String : Any])
btnAction.setTitle("Stop", for: UIControlState.normal)
isBroadcasting = true
}
}
else {
bluetoothPeripheralManager.stopAdvertising()
btnAction.setTitle("Start", for: UIControlState.normal)
isBroadcasting = false
}
}
func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?) {
print ("peripheralManagerDidStartAdvertising()")
if error != nil
{
print(error)
}
}
func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveRead request: CBATTRequest) {
print ("peripheralManager(...didReceiveRead)")
}
func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
var statusMessage = ""
switch peripheral.state {
case CBManagerState.poweredOn:
statusMessage = "Bluetooth Status: Turned On"
case CBManagerState.poweredOff:
if isBroadcasting {
switchBroadcastingState(self)
}
statusMessage = "Bluetooth Status: Turned Off"
case CBManagerState.resetting:
statusMessage = "Bluetooth Status: Resetting"
case CBManagerState.unauthorized:
statusMessage = "Bluetooth Status: Not Authorized"
case CBManagerState.unsupported:
statusMessage = "Bluetooth Status: Not Supported"
default:
statusMessage = "Bluetooth Status: Unknown"
}
print("Bluetooth Status: \(statusMessage)")
}
}
- - - END - - - - -
(Apologies for any code format mistakes.)
Upvotes: 5
Views: 587
Reputation: 2031
I also tried iBeacon Region monitoring with the iPhone 7 (A1778) and on the iPhone 6S (A1688).
I also experience that didEnterRegion
and didExitRegion
is never executed on the iPhone 7. The reason for that maybe that Apple dropped iBeacon micro location on the iPhone 7.
According to the technical specs "iBeacon microlocation" is no longer listed for the iPhone 7. Here are the tech specs of the iPhone 7: https://support.apple.com/kb/SP743?locale=en_US Here are the ones of the iPhone 6S: https://support.apple.com/kb/SP726?locale=en_US
I've tried rebooting and actually it helps to let it work while the app is running in the foreground. Region monitoring in the background is not working at all. It also does not work if you come back to foreground after the app has been in the background.
Upvotes: 0
Reputation: 64941
Lots of people report trouble with bluetooth on iOS 10, but the trouble isn't universal.
Testing with 10.0.2 (14A456) on an iPod Touch 6th Generation model mkh22ll/a, I can successfully scan for beacons and transmit iBeacon using the Locate app for iOS. This is written in Objective C, but uses the same APIs as you are showing. You might try this same app on the problematic device and see if you still have trouble.
Testing another app that is written in Swift 3 on the same device (the app both transmits and receives iBeacon packets), I have verified that it successfully receives iBeacon packets and sends them, too.
The bottom line is that iBeacon transmission and detection on iOS 10 works fine on some devices.
I suspect that bluetooth problems with iOS 10 only happen with certain iPhone hardware models (and perhaps only on certain specific devices of these models) that have somewhat different bluetooth hardware chipsets.
A few things that may help troubleshoot:
Please do update the question with your hardware device.
Upvotes: 3