Version 1.24 add notifications and configure background bluetooth

This commit is contained in:
Garth Vander Houwen 2021-10-06 22:24:45 -07:00
parent b19967f5e4
commit ad59d90e18
4 changed files with 86 additions and 11 deletions

View file

@ -659,7 +659,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.23;
MARKETING_VERSION = 1.24;
PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = NO;
@ -686,7 +686,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.23;
MARKETING_VERSION = 1.24;
PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = NO;

View file

@ -177,9 +177,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
}
else
{
connectToDevice(id: lastConnectedNode)
success = false
}
}
return success
}
@ -423,6 +422,13 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
MessageModel(messageId: decodedInfo.packet.id, messageTimeStamp: decodedInfo.packet.rxTime, fromUserId: decodedInfo.packet.from, toUserId: decodedInfo.packet.to, fromUserLongName: fromUser?.user.longName ?? "Unknown", toUserLongName: toUserLongName, fromUserShortName: fromUser?.user.shortName ?? "???", toUserShortName: toUserShortName, receivedACK: decodedInfo.packet.decoded.wantResponse, messagePayload: messageText, direction: "IN"))
messageData.save()
let manager = LocalNotificationManager()
manager.notifications = [
Notification(id: ("notifiction.id.\(decodedInfo.packet.id)"), title: ("\(fromUser?.user.shortName ?? "???") says \(messageText))"))]
manager.schedule()
manager.listScheduledNotifications()
} else {
print("not a valid UTF-8 sequence")
}

View file

@ -1,8 +1,73 @@
//
// LocalNotificationManager.swift
// MeshtasticClient
//
// Created by Garth Vander Houwen on 10/6/21.
//
import Foundation
import SwiftUI
class LocalNotificationManager {
var notifications = [Notification]()
// Step 1 Request Permissions for notifications
private func requestAuthorization()
{
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
if granted == true && error == nil {
self.scheduleNotifications()
}
}
}
func schedule()
{
UNUserNotificationCenter.current().getNotificationSettings { settings in
switch settings.authorizationStatus {
case .notDetermined:
self.requestAuthorization()
case .authorized, .provisional:
self.scheduleNotifications()
default:
break // Do nothing
}
}
}
// This function iterates over the Notification objects in the notifications array and schedules them for delivery in the future
private func scheduleNotifications()
{
for notification in notifications
{
let content = UNMutableNotificationContent()
content.title = notification.title
content.sound = .default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request = UNNotificationRequest(identifier: notification.id, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { error in
guard error == nil else { return }
print("Notification scheduled! --- ID = \(notification.id)")
}
}
}
// Check and debug what local notifications have been scheduled
func listScheduledNotifications()
{
UNUserNotificationCenter.current().getPendingNotificationRequests { notifications in
for notification in notifications {
print(notification)
}
}
}
}
struct Notification {
var id: String
var title: String
}

View file

@ -41,6 +41,10 @@
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
</array>
<key>UILaunchScreen</key>
<dict/>
<key>UIRequiredDeviceCapabilities</key>