Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何从各种视图控制器场景读取/写入?_Ios_Swift_Bluetooth Lowenergy_Uart - Fatal编程技术网

Ios 如何从各种视图控制器场景读取/写入?

Ios 如何从各种视图控制器场景读取/写入?,ios,swift,bluetooth-lowenergy,uart,Ios,Swift,Bluetooth Lowenergy,Uart,我一直在使用Adafruit基本聊天作为参考 我已经定制了代码,以便与我定制的nordic BLE模块进行通信,以实现基本的UART通信。 写10字节,读10字节。 我可以在UartModuleViewController中读写,但只要我创建一个新的视图控制器并尝试使用相同的peripal.writeValue,应用程序就会在我的第二个ViewController中的peripal.writeValue行抛出错误。 有人能帮我介绍一下如何将同一外设连接到不同的view controller场景,

我一直在使用Adafruit基本聊天作为参考

我已经定制了代码,以便与我定制的nordic BLE模块进行通信,以实现基本的UART通信。 写10字节,读10字节。 我可以在UartModuleViewController中读写,但只要我创建一个新的视图控制器并尝试使用相同的peripal.writeValue,应用程序就会在我的第二个ViewController中的peripal.writeValue行抛出错误。 有人能帮我介绍一下如何将同一外设连接到不同的view controller场景,以便我可以类似地使用写/读功能吗

//This is my write code
let bytes : [UInt8] = [ 0x1A, 0x2B, 0x3C, 0x4D ]
        let Transmitdata = NSData(bytes: bytes, length: bytes.count)
        peripheral.writeValue(Transmitdata as Data, for: txCharacteristic!, type: CBCharacteristicWriteType.withoutResponse)
        print("Data Sent",Transmitdata)
//这是我的阅读代码

let ReceiveData = rxCharacteristic?.value
        if let ReceiveData = ReceiveData {
            let ReceivedNoOfBytes = ReceiveData.count
            var ReceivedByteArray = [UInt8](repeating: 0, count: ReceivedNoOfBytes)
            (ReceiveData as NSData).getBytes(&ReceivedByteArray, length: ReceivedNoOfBytes)
            print("Data Received ",ReceivedByteArray)
我想使用这两个相同的块来读取和写入所有视图控制器?我有10个视图控制器,我想在它们的所有类中使用相同的块 我是swift/iOS的新手,可供参考的信息有限,因此我希望这能帮助更多像我这样的初学者。 请帮忙。 谢谢 纳尔

线程1:EXC_断点代码=1,子代码=0x10042b200

我算出了。 将连接的外围设备从扫描的外围设备阵列中传递,并在我们想要从中心类访问它时将服务uuid引用到外围设备,使用segue将其传递到我们想要的任何视图控制器场景,并将其引用到中心/主类,以便在我们返回主页时不会断开连接查看控制器场景。 谢谢你们的推荐

0x1000d9b78 <+2408>:  uxtb   w2, w9
    0x1000d9b7c <+2412>:  uxtb   w5, w9
    0x1000d9b80 <+2416>:  mov    x6, x10
    0x1000d9b84 <+2420>:  bl     0x1000e0174               ; symbol stub for: function signature specialization <preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage(Swift.StaticString, Swift.StaticString, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never
    0x1000d9b88 <+2424>:  ldr    x8, [x19, #0xab8].  <- This is where it throws an error/exception/fatal error.