私はプリンタXcodeの上IOS迅速な3 - プリンタのBluetooth
でBluetooth経由で印刷するアプリを作成しようとしている、私はプリンタを接続することができるよ、とにもサービスやUUIDさんを見て、しかし、問題は、私がサービスの特徴を見てみると、ゼロであることが分かりました 誰かがその問題についてアイデアを持っていますか?
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
for service in peripheral.services! {
print("Service \(service)\n")
print("Discovering Characteristics for Service : \(service.uuid)")
print(service.characteristics)
}
}
override func viewDidLoad() {
super.viewDidLoad()
centralManager = CBCentralManager(delegate: self, queue: nil)
}
func centralManagerDidUpdateState(_ central: CBCentralManager) {
if #available(iOS 10.0, *){
switch (central.state) {
case CBManagerState.poweredOff:
print("CBCentralManagerState.PoweredOff")
case CBManagerState.unauthorized:
print("CBCentralManagerState.Unauthorized")
break
case CBManagerState.unknown:
print("CBCentralManagerState.Unknown")
break
case CBManagerState.poweredOn:
print("CBCentralManagerState.PoweredOn")
centralManager.scanForPeripherals(withServices: nil, options: nil)
centralManager.scanForPeripherals(withServices: nil, options: nil)
case CBManagerState.resetting:
print("CBCentralManagerState.Resetting")
case CBManagerState.unsupported:
print("CBCentralManagerState.Unsupported")
break
}}else{
switch central.state.rawValue{
case 0:
print("CBCentralManagerState.Unknown")
break
case 1:
print("CBCentralManagerState.Resetting")
case 2:
print("CBCentralManagerState.Unsupported")
break
case 3:
print("This app is not authorised to use Bluetooth low energy")
break
case 4:
print("Bluetooth is currently powered off.")
case 5:
print("Bluetooth is currently powered on and available to use.")
self.centralManager.scanForPeripherals(withServices: nil, options: nil)
break
default:
break
}}}
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
print("name : \(peripheral.name)")
let device = (advertisementData as NSDictionary)
.object(forKey: CBAdvertisementDataLocalNameKey)
as? NSString
if device?.contains(BEAN_NAME) == true {
self.centralManager.stopScan()
self.peripheral = peripheral
self.peripheral.delegate = self
print("peripheral: \(self.peripheral)")
centralManager.connect(peripheral, options: nil)
print("peripheral: \(self.peripheral)")
}
}
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
peripheral.delegate = self
peripheral.discoverServices(nil)
}
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
print(error)
for characteristic in service.characteristics! {
print(anything)
}
func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?) {
print("Sent")
}
への呼び出しは 'ERROR' – preetam
を印刷しようとしてしまいます
- あなたは
discoverCharacteristics:for:
を呼び出す必要がありますエラーはありません@preetam – Anthony'discoverCharacteristics:for'を呼び出す必要がありますhttps://developer.apple.com/reference/corebluetooth/cbperipheral/1518797-発見特性 – Paulw11