SonarQube扫描Swift代码

本文介绍了如何配置和使用SonarQube对Swift代码进行质量扫描。首先下载了sonarqube-6.3和sonar-scanner-3.0.0.702-macosx,接着配置sonar-scanner.properties文件,包括设置URL、登录信息、数据库连接等。然后在项目中创建sonar-project.properties文件,指定项目键、名称和源代码路径。最后通过命令行运行sonar-scanner进行扫描。
摘要由CSDN通过智能技术生成

1.下载 sonarqube-6.3、sonar-scanner-3.0.0.702-macosx

2.启动sonarqube步骤略过(后期补)

3.进入sonar-scanner-3.0.0.702-macosx/conf/sonar-scanner.properties

修改成如下

sonar.host.url=http://localhost:9000
sonar.login=admin
sonar.password=admin
sonar.jdbc.username=root
sonar.jdbc.password=root
sonar.jdbc.url=jdbc:mysql://localhost:3306/SonarQube?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.sourceEncoding=UTF-8
sonar.projectKey=learning-iOS
sonar.projectName

在iOS Swift中连接扫描枪的代码主要分为两个部分:Bluetooth连接和接收扫描数据。 首先,需要在应用中引入CoreBluetooth库。在ViewController中创建一个BLEManager类,并像下面这样定义其属性和方法: ```swift class BLEManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate { var centralManager: CBCentralManager? var peripheral: CBPeripheral? var characteristic:CBCharacteristic? override init() { super.init() centralManager = CBCentralManager(delegate: self, queue: nil) } func centralManagerDidUpdateState(_ central: CBCentralManager) { if central.state == .poweredOn { central.scanForPeripherals(withServices:nil, options: nil) print("Scanning started") } else { print("Bluetooth not available.") } } func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { if (peripheral.name == "Your peripheral name") { self.centralManager?.stopScan() self.peripheral = peripheral self.peripheral?.delegate = self self.centralManager?.connect(self.peripheral!, options: nil) } } func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { if peripheral == self.peripheral { peripheral.discoverServices(nil) print("Connected to your peripheral") } } func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) { for service in peripheral.services! { peripheral.discoverCharacteristics(nil, for: service) } } func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { for characteristic in service.characteristics! { if characteristic.uuid == CBUUID(string: "Your characteristic UUID") { self.characteristic = characteristic peripheral.setNotifyValue(true, for: characteristic) print("Characteristic found") } } } func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { if characteristic == self.characteristic { if let data = characteristic.value { let string = String(data: data, encoding: .utf8)! print("Scanned barcode is: \(string)") } } } } ``` 接着,在ViewController中初始化BLEManager并调用centralManager的方法: ```swift var bleManager: BLEManager? override func viewDidLoad() { super.viewDidLoad() bleManager = BLEManager() } ``` 最后,需要将扫描枪的UUID和特征UUID替换为自己的。这样,应用就能连接扫描枪并接收扫描数据了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值