-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from SiliconLabs/release-2.9.3
BTAPP-2011 | Enable BLE provisioning for 917 sensor demo on IOS
- Loading branch information
Showing
15 changed files
with
411 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILNetworkCheck.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// SILNetworkCheck.swift | ||
// BlueGecko | ||
// | ||
// Created by SovanDas Maity on 23/09/24. | ||
// Copyright © 2024 SiliconLabs. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import Foundation | ||
import Network | ||
|
||
|
||
class SILNetworkCheck: NSObject { | ||
private var browser: NWBrowser? | ||
private var netService: NetService? | ||
private var completion: ((Bool) -> Void)? | ||
|
||
public func requestAuthorization(completion: @escaping (Bool) -> Void) { | ||
self.completion = completion | ||
|
||
// Create parameters, and allow browsing over peer-to-peer link. | ||
let parameters = NWParameters() | ||
parameters.includePeerToPeer = true | ||
|
||
// Browse for a custom service type. | ||
let browser = NWBrowser(for: .bonjour(type: "_bonjour._tcp", domain: nil), using: parameters) | ||
self.browser = browser | ||
browser.stateUpdateHandler = { newState in | ||
switch newState { | ||
case .failed(let error): | ||
print(error.localizedDescription) | ||
case .ready, .cancelled: | ||
break | ||
case let .waiting(error): | ||
print("Local network permission has been denied: \(error)") | ||
self.reset() | ||
self.completion?(false) | ||
default: | ||
break | ||
} | ||
} | ||
|
||
self.netService = NetService(domain: "local.", type:"_lnp._tcp.", name: "LocalNetworkPrivacy", port: 1100) | ||
self.netService?.delegate = self | ||
|
||
self.browser?.start(queue: .main) | ||
self.netService?.publish() | ||
} | ||
|
||
private func reset() { | ||
self.browser?.cancel() | ||
self.browser = nil | ||
self.netService?.stop() | ||
self.netService = nil | ||
} | ||
} | ||
|
||
|
||
|
||
@available(iOS 14.0, *) | ||
extension SILNetworkCheck : NetServiceDelegate { | ||
public func netServiceDidPublish(_ sender: NetService) { | ||
self.reset() | ||
print("Local network permission has been granted") | ||
completion?(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.