mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 07:06:11 -04:00
Fix the crash when an endpoint without a UTF8 name is discovered
This commit is contained in:
@@ -120,10 +120,13 @@ class Model: ObservableObject {
|
||||
|
||||
extension Model: DiscovererDelegate {
|
||||
func discoverer(_ discoverer: Discoverer, didFind endpointID: EndpointID, with context: Data) {
|
||||
guard let endpointName = String(data: context, encoding: .utf8) else {
|
||||
return
|
||||
}
|
||||
let endpoint = DiscoveredEndpoint(
|
||||
id: UUID(),
|
||||
endpointID: endpointID,
|
||||
endpointName: String(data: context, encoding: .utf8)!
|
||||
endpointName: endpointName
|
||||
)
|
||||
endpoints.insert(endpoint, at: 0)
|
||||
}
|
||||
@@ -138,10 +141,13 @@ extension Model: DiscovererDelegate {
|
||||
|
||||
extension Model: AdvertiserDelegate {
|
||||
func advertiser(_ advertiser: Advertiser, didReceiveConnectionRequestFrom endpointID: EndpointID, with context: Data, connectionRequestHandler: @escaping (Bool) -> Void) {
|
||||
guard let endpointName = String(data: context, encoding: .utf8) else {
|
||||
return
|
||||
}
|
||||
let endpoint = DiscoveredEndpoint(
|
||||
id: UUID(),
|
||||
endpointID: endpointID,
|
||||
endpointName: String(data: context, encoding: .utf8)!
|
||||
endpointName: endpointName
|
||||
)
|
||||
endpoints.insert(endpoint, at: 0)
|
||||
connectionRequestHandler(true)
|
||||
|
||||
Reference in New Issue
Block a user