2016-09-21 14 views
0

最近Xcode 8.0をダウンロードし、コアbluetoothを使用している以前のプロジェクトを実行しようとしました。Xcode 8.0 CBCentralManager問題

func centralManagerDidUpdateState(central: CBCentralManager) 
{ 
    print("state is \(central.state.rawValue)") 
    if (central.state == CBCentralManagerState.PoweredOn) 
    { 
     self.centralManager?.scanForPeripheralsWithServices([serviceUUID], options: nil) 
    } 
    else 
    { 
     // do something like alert the user that ble is not on 
    } 
} 

以前 central.stateCBCentralManagerState型を返すだろう、私は すべての作品SWIFT 2.3で互換性のためにビルド設定に 使用レガシー・スウィフト言語バージョンを有効にしているが、一つの問題が発生しましたintとして、今すぐ返す CBManagerState私は

に変更しました。

CBManagerStateはIOS 10+でのみサポートされていますが、IOS 8.3+用にビルドしたいのですが、どのようにコードを変更できますか?

UPDATE 私も迅速3.0に変換したプロジェクトが、それでも同じ問題なので、私は10以下のiOS版と携帯電話でこのプロジェクトを実行することができますか?

答えて

3

最も簡単な方法は、単に列挙値にショートハンド基準を使用することです:今、あなたのコードは、エラーや警告なしでコンパイルされます

func centralManagerDidUpdateState(central: CBCentralManager) 
{ 
    print("state is \(central.state.rawValue)") 
    if (central.state == .PoweredOn) 
    { 
     self.centralManager?.scanForPeripheralsWithServices([serviceUUID], options: nil) 
    } 
    else 
    { 
     // do something like alert the user that ble is not on 
    } 

} 

と、すべてのターゲット

に正しく動作します
関連する問題