mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Fix messages crash V 1.23
This commit is contained in:
parent
1c4984d32a
commit
b19967f5e4
4 changed files with 70 additions and 16 deletions
|
|
@ -26,6 +26,7 @@
|
|||
DD8EDE9426F97A2B00A5A10B /* SwiftProtobuf in Frameworks */ = {isa = PBXBuildFile; productRef = DD8EDE9326F97A2B00A5A10B /* SwiftProtobuf */; };
|
||||
DD90860C26F684AF00DC5189 /* BatteryIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD90860B26F684AF00DC5189 /* BatteryIcon.swift */; };
|
||||
DD90860E26F69BAE00DC5189 /* NodeMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD90860D26F69BAE00DC5189 /* NodeMap.swift */; };
|
||||
DD913639270DFF4C00D7ACF3 /* LocalNotificationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD913638270DFF4C00D7ACF3 /* LocalNotificationManager.swift */; };
|
||||
DDAF8C5326EB1DF10058C060 /* BLEManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAF8C5226EB1DF10058C060 /* BLEManager.swift */; };
|
||||
DDAF8C5826ED07FD0058C060 /* mesh.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAF8C5726ED07FD0058C060 /* mesh.pb.swift */; };
|
||||
DDAF8C5D26ED09490058C060 /* portnums.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAF8C5C26ED09490058C060 /* portnums.pb.swift */; };
|
||||
|
|
@ -85,6 +86,7 @@
|
|||
DD90860A26F645B700DC5189 /* MeshtasticClient.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MeshtasticClient.entitlements; sourceTree = "<group>"; };
|
||||
DD90860B26F684AF00DC5189 /* BatteryIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryIcon.swift; sourceTree = "<group>"; };
|
||||
DD90860D26F69BAE00DC5189 /* NodeMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeMap.swift; sourceTree = "<group>"; };
|
||||
DD913638270DFF4C00D7ACF3 /* LocalNotificationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalNotificationManager.swift; sourceTree = "<group>"; };
|
||||
DDAF8C5226EB1DF10058C060 /* BLEManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BLEManager.swift; sourceTree = "<group>"; };
|
||||
DDAF8C5726ED07FD0058C060 /* mesh.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = mesh.pb.swift; sourceTree = "<group>"; };
|
||||
DDAF8C5C26ED09490058C060 /* portnums.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = portnums.pb.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -314,6 +316,7 @@
|
|||
DDC2E1A626CEB3400042C5E4 /* LocationHelper.swift */,
|
||||
DDAF8C6D26ED19040058C060 /* Extensions.swift */,
|
||||
DD47E3D126F1210600029299 /* HelperFunctions.swift */,
|
||||
DD913638270DFF4C00D7ACF3 /* LocalNotificationManager.swift */,
|
||||
);
|
||||
path = Helpers;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -460,6 +463,7 @@
|
|||
DDC2E1A726CEB3400042C5E4 /* LocationHelper.swift in Sources */,
|
||||
DD47E3D226F1210600029299 /* HelperFunctions.swift in Sources */,
|
||||
DDAF8C5F26ED09B50058C060 /* radioconfig.pb.swift in Sources */,
|
||||
DD913639270DFF4C00D7ACF3 /* LocalNotificationManager.swift in Sources */,
|
||||
DDAF8C5326EB1DF10058C060 /* BLEManager.swift in Sources */,
|
||||
DD90860E26F69BAE00DC5189 /* NodeMap.swift in Sources */,
|
||||
DD47E3DB26F3901B00029299 /* Channels.swift in Sources */,
|
||||
|
|
@ -655,7 +659,7 @@
|
|||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.22;
|
||||
MARKETING_VERSION = 1.23;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SUPPORTS_MACCATALYST = NO;
|
||||
|
|
@ -682,7 +686,7 @@
|
|||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.22;
|
||||
MARKETING_VERSION = 1.23;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SUPPORTS_MACCATALYST = NO;
|
||||
|
|
|
|||
|
|
@ -135,18 +135,23 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
|
||||
// Send Broadcast Message
|
||||
public func sendMessage(message: String) -> Bool
|
||||
{ var success = true
|
||||
if connectedPeripheral == nil || connectedPeripheral!.peripheral.state != CBPeripheralState.connected {
|
||||
success = false
|
||||
if lastConnectedNode.count > 10 {
|
||||
connectToDevice(id: lastConnectedNode)
|
||||
//Thread.sleep(forTimeInterval: 3)
|
||||
}
|
||||
{
|
||||
|
||||
var success = true
|
||||
|
||||
// Return false if we are not properly connected to a device, handle retry logic in the view for now
|
||||
if connectedPeripheral == nil || connectedPeripheral!.peripheral.state != CBPeripheralState.connected || self.connectedNode == nil {
|
||||
|
||||
|
||||
if connectedPeripheral != nil && self.connectedNode == nil {
|
||||
self.disconnectDevice()
|
||||
// Lets disconnect and then reconnect a second later
|
||||
}
|
||||
success = false
|
||||
}
|
||||
else {
|
||||
|
||||
let messageModel = MessageModel(messageId: 0, messageTimeStamp: UInt32(Date().timeIntervalSince1970), fromUserId: self.connectedNode.id, toUserId: broadcastNodeId, fromUserLongName: self.connectedNode.user.longName, toUserLongName: "Broadcast", fromUserShortName: self.connectedNode.user.shortName, toUserShortName: "BC", receivedACK: false, messagePayload: message, direction: "OUT")
|
||||
let messageModel = MessageModel(messageId: 0, messageTimeStamp: UInt32(Date().timeIntervalSince1970), fromUserId: self.connectedNode.num, toUserId: broadcastNodeId, fromUserLongName: self.connectedNode.user.longName, toUserLongName: "Broadcast", fromUserShortName: self.connectedNode.user.shortName, toUserShortName: "BC", receivedACK: false, messagePayload: message, direction: "OUT")
|
||||
let dataType = PortNum.textMessageApp
|
||||
let payloadData: Data = message.data(using: String.Encoding.utf8)!
|
||||
|
||||
|
|
@ -182,25 +187,45 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
// Disconnect Peripheral Event
|
||||
func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?)
|
||||
{
|
||||
// Start a Scan so the disconnected peripheral is moved to the peripherals[]
|
||||
self.startScanning()
|
||||
|
||||
if let e = error {
|
||||
print("Central disconnected because \(e)")
|
||||
let errorCode = (e as NSError).code
|
||||
|
||||
if errorCode == 6 { // The connection has timed out unexpectedly.
|
||||
// Happens when device is manually reset
|
||||
|
||||
}
|
||||
else if errorCode == 7 { // The specified device has disconnected from us.
|
||||
|
||||
// Check if the peripheral is still visible and then reconnect
|
||||
|
||||
}
|
||||
// connectToDevice(id: peripheral.identifier.uuidString)
|
||||
} else {
|
||||
print("Central disconnected! (no error)")
|
||||
}
|
||||
|
||||
if(peripheral.identifier == connectedPeripheral.peripheral.identifier){
|
||||
// if
|
||||
connectedPeripheral = nil
|
||||
connectedNode = nil
|
||||
}
|
||||
print("Peripheral disconnected: " + peripheral.name!)
|
||||
self.startScanning()
|
||||
|
||||
}
|
||||
|
||||
// Discover Services Event
|
||||
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
|
||||
|
||||
if let e = error {
|
||||
print("Discover Services error \(e)")
|
||||
//let errorCode = (e as NSError).code
|
||||
|
||||
}
|
||||
|
||||
guard let services = peripheral.services else { return }
|
||||
|
||||
for service in services
|
||||
|
|
@ -218,9 +243,14 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
// Discover Characteristics Event
|
||||
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?)
|
||||
{
|
||||
guard let characteristics = service.characteristics else { return }
|
||||
if let e = error {
|
||||
|
||||
print("Discover Characteristics error \(e)")
|
||||
}
|
||||
|
||||
guard let characteristics = service.characteristics else { return }
|
||||
|
||||
for characteristic in characteristics {
|
||||
for characteristic in characteristics {
|
||||
|
||||
switch characteristic.uuid
|
||||
{
|
||||
|
|
@ -255,6 +285,11 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
// Data Read / Update Characteristic Event
|
||||
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?)
|
||||
{
|
||||
if let e = error {
|
||||
|
||||
print("didUpdateValueFor Characteristic error \(e)")
|
||||
}
|
||||
|
||||
switch characteristic.uuid
|
||||
{
|
||||
case FROMNUM_UUID:
|
||||
|
|
|
|||
8
MeshtasticClient/Helpers/LocalNotificationManager.swift
Normal file
8
MeshtasticClient/Helpers/LocalNotificationManager.swift
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
//
|
||||
// LocalNotificationManager.swift
|
||||
// MeshtasticClient
|
||||
//
|
||||
// Created by Garth Vander Houwen on 10/6/21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
|
@ -91,11 +91,18 @@ struct Messages: View {
|
|||
typingMessage = ""
|
||||
}
|
||||
else {
|
||||
let timer = Timer.scheduledTimer(withTimeInterval: 3.0, repeats: false) { (timer) in
|
||||
if bleManager.sendMessage(message: typingMessage) {
|
||||
typingMessage = ""
|
||||
if bleManager.lastConnectedNode.count > 10 {
|
||||
if bleManager.peripherals.contains(where: { $0.id == bleManager.lastConnectedNode }) {
|
||||
bleManager.connectToDevice(id: bleManager.lastConnectedNode)
|
||||
let timer = Timer.scheduledTimer(withTimeInterval: 3.0, repeats: false) { (timer) in
|
||||
|
||||
if bleManager.sendMessage(message: typingMessage) {
|
||||
typingMessage = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} ) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue