由于“内部”保护级别,无法访问sharedInstance

时间:2018-06-29 20:34:33

标签: ios swift swift4 core-bluetooth obd-ii

我已经导入了一个cocoapod,可以将我的应用程序连接到低功耗蓝牙设备。当尝试访问该类的实例时,由于“内部”保护级别,我收到错误sharedInstance无法访问的错误。为什么会出现此错误?

下面是包含实例的类。

import Foundation
import CoreBluetooth
import Alamofire
import SwiftyJSON

public class OBD2_BLE: NSObject, CBCentralManagerDelegate, 
CBPeripheralDelegate {

    var centralManager: CBCentralManager!
    var obd2: CBPeripheral?
    var dataCharacteristic:CBCharacteristic?

    var obdCommands:[String: String]! = [
        "speed": "010D",
        "vin": "0902"
    ]

    var configurationCommands = [
        "ATE0",
        "ATH0",
        "ATS0",
        "ATL0",
        "ATSP0"
    ]

    var obdResponse:[UInt8] = []
    let endOfResponseNotificationIdentifier = 
Notification.Name("endOfResponseNotificationIdentifier")

    // setupOutput is expected output from device after reset (no prior 
configuration)
    // partialsetupOutput is expected output from device without reset 
(device remained configured from previous run)
    let restartSetupOutput = "\r\rELM327 
v1.5\r\r>ATE0\rOK\r\r>OK\r\r>OK\r\r>OK\r\r>OK\r\r>"
    let setupOutput = "ATE0\rOK\r\r>OK\r\r>OK\r\r>OK\r\r>OK\r\r>"
    let partialsetupOutput = "OK\r\r>OK\r\r>OK\r\r>OK\r\r>OK\r\r>"
    var setupComplete = false

    var vinNumber:String?

    static let sharedInstance = OBD2_BLE()
    private static let setup = OBD2_BLESetup()

    class func setup(restoreId: String){
        OBD2_BLE.setup.restoreId = restoreId

    }


    public override init() {
        super.init()

        let restoreId = OBD2_BLE.setup.restoreId

        if restoreId == nil {
            self.initWithoutBackground()
        } else {
            self.initWithBackground(restoreId: restoreId!)
        }
    }

以下是我尝试访问的实例

import UIKit
import CoreBluetooth
import OBD2_BLE

class BluetoothViewController: UIViewController, UITableViewDelegate {

    @IBOutlet weak var bluetoothTableView: UITableView!
    var deviceArray = [CBPeripheral]()

    var centralManager : CBCentralManager!
    var currentPeripheral : CBPeripheral?

    let obd2 = OBD2_BLE.sharedInstance // Where i receive error

    var currentRow : IndexPath?

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        centralManager = CBCentralManager(delegate: self, queue: nil)
        bluetoothTableView.dataSource = self
        bluetoothTableView.delegate = self

    }

0 个答案:

没有答案