2016-11-08 3 views
0

私は初心者であり、BLEの特徴を示す簡単なプログラムを開発しようとします。私は、印刷によってそれを再度確認し 、と私は、データがなくなって見る私は目標特性segueでデータが失われました(xcode8.0)

myCharacteristicUUID_1 : (
    "Manufacturer Name String", 
    "Model Number String", 
    "Serial Number String", 
    "Hardware Revision String", 
    "Firmware Revision String", 
    "Software Revision String" 
) 

のUUIDを撮影し、そのプリントによって確認しかし、オーバーライドでFUNC(どれセグエのために:UIStoryboardSegue、送信者?)準備します以下のように;

myCharacteristicUUID_2 : (
) 

私は他のタイプの値(文字列、テキストなど)を引き渡すことができますが、BLEから取得したデータは処理できません。私がBLEのデータをセグーで使用するときに何をしなければならないかを誰かが指摘できますか? 以下は私のコードです。

func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor targetService: CBService, error: Error?) { 

    if error != nil { 
     print("Characteristic NOT found : \(error)") 

    } 

    let foundCharacteristics = targetService.characteristics 

    for c in foundCharacteristics! as [CBCharacteristic] { 

     myCharacteristicUUID.add(c.uuid) 

    } 

    print("myCharacteristicUUID_1 : \(myCharacteristicUUID)") 

} 

// prepare for segue 
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 

    if (segue.identifier == "mySegue") { 

     print("myCharacteristicUUID_2 : \(myCharacteristicUUID)") 

     let mySecondViewController : SecondViewController = segue.destination as! SecondViewController 

     mySecondViewController.relayedFoundCharacteristicUUID = myCharacteristicUUID 

    } 

} 
+0

「myCharacteristicUUID」タイプとは何ですか?機能が完了したときに永続化されていないように私に見てください。 –

+0

myCharacteristicUUIDをNSMutableArrayに設定しました。私は数週間前に素早く勉強し始め、まだ苦労しています。 – sandalwalk

+0

'myCharacteristicUUID'をコードに宣言する方法を教えてください。 –

答えて

0

が正しく読み取られなかった理由がここにあります。 performSegueの場所をご覧ください。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 

    selectedService = myService[indexPath.row] as! CBService 
    print("Selected_service : \(selectedService)") 

    self.peripheral.discoverCharacteristics(nil, for:selectedService as CBService!) 

    //performSegue(withIdentifier: "mySegue", sender: nil) 
    // I used to performed segue here. This was the reason myCharacterisitcUUID was empty. 


} 

// find the characteristics for the targetService 

func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor targetService: CBService, error: Error?) { 

    if error != nil { 
     print("Characteristic NOT found : \(error)") 

    } 

    foundCharacteristics = targetService.characteristics! 

    for c in foundCharacteristics as [CBCharacteristic] { 

     self.myCharacteristicUUID.add(c.uuid) 

    } 
    // segue should be performed here ! This change worked! 
    performSegue(withIdentifier: "mySegue", sender: nil) 
} 
関連する問題