mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Merge pull request #331 from meshtastic/try-clear-channels
Try clear channels
This commit is contained in:
commit
f3f06bf9ee
1 changed files with 24 additions and 19 deletions
|
|
@ -446,6 +446,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject {
|
|||
connectedPeripheral.longName = myInfo?.bleName ?? NSLocalizedString("unknown", comment: "Unknown")
|
||||
}
|
||||
}
|
||||
tryClearExistingChannels()
|
||||
}
|
||||
// NodeInfo
|
||||
if decodedInfo.nodeInfo.num > 0 && !invalidVersion {
|
||||
|
|
@ -982,25 +983,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject {
|
|||
let fetchMyInfoRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest.init(entityName: "MyInfoEntity")
|
||||
fetchMyInfoRequest.predicate = NSPredicate(format: "myNodeNum == %lld", Int64(connectedPeripheral.num))
|
||||
|
||||
do {
|
||||
guard let fetchedMyInfo = try context!.fetch(fetchMyInfoRequest) as? [MyInfoEntity] else {
|
||||
return false
|
||||
}
|
||||
if fetchedMyInfo.count == 1 {
|
||||
guard let mutableChannels = fetchedMyInfo[0].channels!.mutableCopy() as? NSMutableOrderedSet else {
|
||||
return false
|
||||
}
|
||||
mutableChannels.removeAllObjects()
|
||||
fetchedMyInfo[0].channels = mutableChannels
|
||||
do {
|
||||
try context!.save()
|
||||
} catch {
|
||||
print("Failed to clear existing channels from local app database")
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
print("Failed to find a node MyInfo to save these channels to")
|
||||
}
|
||||
tryClearExistingChannels()
|
||||
let decodedString = base64UrlString.base64urlToBase64()
|
||||
if let decodedData = Data(base64Encoded: decodedString) {
|
||||
do {
|
||||
|
|
@ -1891,6 +1874,28 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public func tryClearExistingChannels() {
|
||||
//Before we get started delete the existing channels from the myNodeInfo
|
||||
let fetchMyInfoRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest.init(entityName: "MyInfoEntity")
|
||||
fetchMyInfoRequest.predicate = NSPredicate(format: "myNodeNum == %lld", Int64(connectedPeripheral.num))
|
||||
|
||||
do {
|
||||
let fetchedMyInfo = try context!.fetch(fetchMyInfoRequest) as! [MyInfoEntity]
|
||||
if fetchedMyInfo.count == 1 {
|
||||
let mutableChannels = fetchedMyInfo[0].channels!.mutableCopy() as! NSMutableOrderedSet
|
||||
mutableChannels.removeAllObjects()
|
||||
fetchedMyInfo[0].channels = mutableChannels
|
||||
do {
|
||||
try context!.save()
|
||||
} catch {
|
||||
print("Failed to clear existing channels from local app database")
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
print("Failed to find a node MyInfo to save these channels to")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - CB Central Manager implmentation
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue