diff --git a/Meshtastic/Persistence/Persistence.swift b/Meshtastic/Persistence/Persistence.swift index d4a86742..1c768ccf 100644 --- a/Meshtastic/Persistence/Persistence.swift +++ b/Meshtastic/Persistence/Persistence.swift @@ -1,8 +1,8 @@ // // Persistence.swift -// CoreDataSample +// Meshtastic // -// Created by Garth Vander Houwen on 11/28/21. +// Copyright(c) Garth Vander Houwen 11/28/21. // import CoreData diff --git a/Meshtastic/Persistence/PositionEntityExtension.swift b/Meshtastic/Persistence/PositionEntityExtension.swift index b671e6e8..75ba3f4b 100644 --- a/Meshtastic/Persistence/PositionEntityExtension.swift +++ b/Meshtastic/Persistence/PositionEntityExtension.swift @@ -1,3 +1,10 @@ +// +// PersistenceEntityExtenstion.swift +// Meshtastic +// +// Copyright(c) Garth Vander Houwen 11/28/21. +// + import CoreData import CoreLocation import MapKit diff --git a/Meshtastic/Persistence/UserEntityExtension.swift b/Meshtastic/Persistence/UserEntityExtension.swift index 1d2dd3da..6d9f5699 100644 --- a/Meshtastic/Persistence/UserEntityExtension.swift +++ b/Meshtastic/Persistence/UserEntityExtension.swift @@ -1,6 +1,6 @@ // // UserEntityExtension.swift -// MeshtasticApple +// Meshtastic // // Copyright(c) Garth Vander Houwen 6/3/22. // diff --git a/Meshtastic/Views/Bluetooth/Connect.swift b/Meshtastic/Views/Bluetooth/Connect.swift index 58711e4e..6ee95a32 100644 --- a/Meshtastic/Views/Bluetooth/Connect.swift +++ b/Meshtastic/Views/Bluetooth/Connect.swift @@ -26,6 +26,20 @@ struct Connect: View { @State var presentingSwitchPreferredPeripheral = false @State var selectedPeripherialId = "" + init () { + let notificationCenter = UNUserNotificationCenter.current() + notificationCenter.getNotificationSettings(completionHandler: { (settings) in + if settings.authorizationStatus == .notDetermined { + UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in + if success { + print("Notifications are all set!") + } else if let error = error { + print(error.localizedDescription) + } + } + } + }) + } var body: some View { NavigationStack { @@ -279,18 +293,9 @@ struct Connect: View { .onAppear(perform: { self.bleManager.context = context self.bleManager.userSettings = userSettings - - // Ask for notification permission - UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in - if success { - print("Notifications are all set!") - } else if let error = error { - print(error.localizedDescription) - } - } }) } -#if canImport(ActivityKit) + #if canImport(ActivityKit) func startNodeActivity() { if #available(iOS 16.2, *) { liveActivityStarted = true @@ -330,29 +335,7 @@ struct Connect: View { } } } -#endif - -#if os(iOS) - func postNotification() { - let timerSeconds = 60 - let content = UNMutableNotificationContent() - content.title = "Mesh Live Activity Over" - content.body = "Your timed mesh live activity is over." - let trigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval(timerSeconds), repeats: false) - let uuidString = UUID().uuidString - let request = UNNotificationRequest(identifier: uuidString, - content: content, trigger: trigger) - let notificationCenter = UNUserNotificationCenter.current() - notificationCenter.add(request) { (error) in - if error != nil { - // Handle any errors. - print("Error posting local notification: \(error?.localizedDescription ?? "no description")") - } else { - print("Posted local notification.") - } - } - } -#endif + #endif func didDismissSheet() { bleManager.disconnectPeripheral(reconnect: false) diff --git a/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift b/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift index 776e98a1..71b4bbf2 100644 --- a/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift +++ b/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift @@ -43,8 +43,8 @@ struct MapViewSwiftUI: UIViewRepresentable { let span = MKCoordinateSpan(latitudeDelta: 0.003, longitudeDelta: 0.003) let center = (latest.count > 0 && userTrackingMode == MKUserTrackingMode.none) ? latest[0].coordinate : LocationHelper.currentLocation let region = MKCoordinateRegion(center: center, span: span) - mapView.setRegion(region, animated: true) mapView.addAnnotations(showNodeHistory ? positions : latest) + mapView.setRegion(region, animated: true) // Set user (phone gps) tracking options mapView.setUserTrackingMode(userTrackingMode, animated: true) if userTrackingMode == MKUserTrackingMode.none { @@ -120,7 +120,7 @@ struct MapViewSwiftUI: UIViewRepresentable { let latest = positions .filter { $0.latest == true } .sorted { $0.nodePosition?.num ?? 0 > $1.nodePosition?.num ?? -1 } - let annotationCount = waypoints.count + (showNodeHistory || showRouteLines ? positions.count : latest.count) + let annotationCount = waypoints.count + (showNodeHistory ? positions.count : latest.count) if annotationCount > mapView.annotations.count { print("Annotation Count: \(annotationCount) Map Annotations: \(mapView.annotations.count)") if showRouteLines { @@ -150,23 +150,24 @@ struct MapViewSwiftUI: UIViewRepresentable { } mapView.removeAnnotations(mapView.annotations) mapView.addAnnotations(waypoints) - mapView.setUserTrackingMode(userTrackingMode, animated: true) - if userTrackingMode == MKUserTrackingMode.none { mapView.showsUserLocation = false - mapView.addAnnotations(showNodeHistory ? positions : latest) if recenter { if latest.count == 1 { - mapView.fit(annotations:showNodeHistory ? positions : latest, andShow: false) + mapView.fit(annotations:showNodeHistory ? positions : latest, andShow: true) } else { + mapView.addAnnotations(showNodeHistory ? positions : latest) mapView.fitAllAnnotations() } + } else { + mapView.addAnnotations(showNodeHistory ? positions : latest) } } else { // Centering Done by tracking mode mapView.addAnnotations(showNodeHistory ? positions : latest) mapView.showsUserLocation = true } + mapView.setUserTrackingMode(userTrackingMode, animated: true) } } }