diff --git a/Meshtastic Client.xcodeproj/project.pbxproj b/Meshtastic Client.xcodeproj/project.pbxproj index 1a2e70d0..84f3004b 100644 --- a/Meshtastic Client.xcodeproj/project.pbxproj +++ b/Meshtastic Client.xcodeproj/project.pbxproj @@ -8,6 +8,10 @@ /* Begin PBXBuildFile section */ C9483F6D2773017500998F6B /* MapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9483F6C2773017500998F6B /* MapView.swift */; }; + C9697F9B2793366500250207 /* offline_map.mbtiles in Resources */ = {isa = PBXBuildFile; fileRef = C9697F9A2793366500250207 /* offline_map.mbtiles */; }; + C9697F9D279336B700250207 /* LocalMBTileOverlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9697F9C279336B700250207 /* LocalMBTileOverlay.swift */; }; + C9697FA527933B8C00250207 /* SQLite in Frameworks */ = {isa = PBXBuildFile; productRef = C9697FA427933B8C00250207 /* SQLite */; }; + C9697FA72793F9FB00250207 /* MTAppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9697FA62793F9FB00250207 /* MTAppDelegate.swift */; }; C9A7BC1027759A9600760B50 /* PositionAnnotationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9A7BC0F27759A9600760B50 /* PositionAnnotationView.swift */; }; C9A88B55278B503C00BD810A /* MapViewModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9A88B54278B503C00BD810A /* MapViewModule.swift */; }; C9A88B57278B559900BD810A /* apponly.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9A88B56278B559900BD810A /* apponly.pb.swift */; }; @@ -74,6 +78,9 @@ /* Begin PBXFileReference section */ C9483F6C2773017500998F6B /* MapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapView.swift; sourceTree = ""; }; + C9697F9A2793366500250207 /* offline_map.mbtiles */ = {isa = PBXFileReference; lastKnownFileType = file; path = offline_map.mbtiles; sourceTree = ""; }; + C9697F9C279336B700250207 /* LocalMBTileOverlay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalMBTileOverlay.swift; sourceTree = ""; }; + C9697FA62793F9FB00250207 /* MTAppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTAppDelegate.swift; sourceTree = ""; }; C9A7BC0F27759A9600760B50 /* PositionAnnotationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PositionAnnotationView.swift; sourceTree = ""; }; C9A88B54278B503C00BD810A /* MapViewModule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapViewModule.swift; sourceTree = ""; }; C9A88B56278B559900BD810A /* apponly.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = apponly.pb.swift; sourceTree = ""; }; @@ -132,6 +139,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + C9697FA527933B8C00250207 /* SQLite in Frameworks */, DD5394FC276993AD00AD86B1 /* SwiftProtobuf in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -159,6 +167,7 @@ C9A7BC0E27759A6800760B50 /* Custom */, C9483F6C2773017500998F6B /* MapView.swift */, C9A88B54278B503C00BD810A /* MapViewModule.swift */, + C9697F9C279336B700250207 /* LocalMBTileOverlay.swift */, ); path = Map; sourceTree = ""; @@ -258,6 +267,7 @@ DDC2E18826CE24EE0042C5E4 /* Model */, DDC2E18926CE24F70042C5E4 /* Resources */, DDC2E15726CE248E0042C5E4 /* MeshtasticClientApp.swift */, + C9697FA62793F9FB00250207 /* MTAppDelegate.swift */, DDC2E16526CE248F0042C5E4 /* Info.plist */, DDC2E15D26CE248F0042C5E4 /* Preview Content */, ); @@ -316,6 +326,7 @@ DDC2E18926CE24F70042C5E4 /* Resources */ = { isa = PBXGroup; children = ( + C9697F9A2793366500250207 /* offline_map.mbtiles */, DDC2E15B26CE248F0042C5E4 /* Assets.xcassets */, ); path = Resources; @@ -383,6 +394,7 @@ name = MeshtasticClient; packageProductDependencies = ( DD5394FB276993AD00AD86B1 /* SwiftProtobuf */, + C9697FA427933B8C00250207 /* SQLite */, ); productName = MeshtasticClient; productReference = DDC2E15426CE248E0042C5E4 /* MeshtasticClient.app */; @@ -435,6 +447,7 @@ TargetAttributes = { DDC2E15326CE248E0042C5E4 = { CreatedOnToolsVersion = 12.5.1; + LastSwiftMigration = 1320; }; DDC2E16926CE248F0042C5E4 = { CreatedOnToolsVersion = 12.5.1; @@ -457,6 +470,7 @@ mainGroup = DDC2E14B26CE248E0042C5E4; packageReferences = ( DD5394FA276993AD00AD86B1 /* XCRemoteSwiftPackageReference "swift-protobuf" */, + C9697FA327933B8C00250207 /* XCRemoteSwiftPackageReference "SQLite.swift" */, ); productRefGroup = DDC2E15526CE248E0042C5E4 /* Products */; projectDirPath = ""; @@ -476,6 +490,7 @@ files = ( DDC2E15F26CE248F0042C5E4 /* Preview Assets.xcassets in Resources */, DDC2E15C26CE248F0042C5E4 /* Assets.xcassets in Resources */, + C9697F9B2793366500250207 /* offline_map.mbtiles in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -551,10 +566,12 @@ DDAF8C6326ED0A230058C060 /* admin.pb.swift in Sources */, C9483F6D2773017500998F6B /* MapView.swift in Sources */, DDAF8C5826ED07FD0058C060 /* mesh.pb.swift in Sources */, + C9697FA72793F9FB00250207 /* MTAppDelegate.swift in Sources */, DD8169FB271F1F3A00F4AB02 /* MeshLog.swift in Sources */, DD2E65262767A01F00E45FC5 /* NodeDetail.swift in Sources */, C9A88B57278B559900BD810A /* apponly.pb.swift in Sources */, DD47E3D926F3093800029299 /* MessageBubble.swift in Sources */, + C9697F9D279336B700250207 /* LocalMBTileOverlay.swift in Sources */, DD8169F9271F1A6100F4AB02 /* MeshLogger.swift in Sources */, DD539502276DAA6A00AD86B1 /* MapLocation.swift in Sources */, DDAF8C6726ED0C8C0058C060 /* remote_hardware.pb.swift in Sources */, @@ -720,6 +737,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = MeshtasticClient/MeshtasticClient.entitlements; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 15; @@ -737,6 +755,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = YES; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2,6"; }; @@ -748,6 +767,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = MeshtasticClient/MeshtasticClient.entitlements; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 15; @@ -896,6 +916,14 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ + C9697FA327933B8C00250207 /* XCRemoteSwiftPackageReference "SQLite.swift" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/stephencelis/SQLite.swift.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 0.9.2; + }; + }; DD5394FA276993AD00AD86B1 /* XCRemoteSwiftPackageReference "swift-protobuf" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/apple/swift-protobuf.git"; @@ -907,6 +935,11 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + C9697FA427933B8C00250207 /* SQLite */ = { + isa = XCSwiftPackageProductDependency; + package = C9697FA327933B8C00250207 /* XCRemoteSwiftPackageReference "SQLite.swift" */; + productName = SQLite; + }; DD5394FB276993AD00AD86B1 /* SwiftProtobuf */ = { isa = XCSwiftPackageProductDependency; package = DD5394FA276993AD00AD86B1 /* XCRemoteSwiftPackageReference "swift-protobuf" */; diff --git a/Meshtastic Client.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Meshtastic Client.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 1cb05e42..c0572681 100644 --- a/Meshtastic Client.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Meshtastic Client.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,6 +1,15 @@ { "object": { "pins": [ + { + "package": "SQLite.swift", + "repositoryURL": "https://github.com/stephencelis/SQLite.swift.git", + "state": { + "branch": null, + "revision": "60a65015f6402b7c34b9a924f755ca0a73afeeaa", + "version": "0.13.1" + } + }, { "package": "SwiftProtobuf", "repositoryURL": "https://github.com/apple/swift-protobuf.git", diff --git a/Meshtastic Client.xcodeproj/project.xcworkspace/xcuserdata/joshuapirihi.xcuserdatad/UserInterfaceState.xcuserstate b/Meshtastic Client.xcodeproj/project.xcworkspace/xcuserdata/joshuapirihi.xcuserdatad/UserInterfaceState.xcuserstate index 85e4e4d5..66abbf05 100644 Binary files a/Meshtastic Client.xcodeproj/project.xcworkspace/xcuserdata/joshuapirihi.xcuserdatad/UserInterfaceState.xcuserstate and b/Meshtastic Client.xcodeproj/project.xcworkspace/xcuserdata/joshuapirihi.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MeshtasticClient/Info.plist b/MeshtasticClient/Info.plist index b5b09295..74217155 100644 --- a/MeshtasticClient/Info.plist +++ b/MeshtasticClient/Info.plist @@ -2,10 +2,27 @@ + UISupportsDocumentBrowser + + LSSupportsOpeningDocumentsInPlace + CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleDisplayName Meshtastic + CFBundleDocumentTypes + + + CFBundleTypeName + MBTiles Map + LSHandlerRank + Default + LSItemContentTypes + + gvh.MeshtasticClient.mbtiles + + + CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier @@ -29,7 +46,7 @@ NSBluetoothAlwaysUsageDescription We use bluetooth to connect to nearby Meshtastic Devices NSBluetoothPeripheralUsageDescription - Bluetooth is used to connect an iPhone to a user's meshtastic device to allow text messaging and location data for the mesh network. + Bluetooth is used to connect an iPhone to a user's meshtastic device to allow text messaging and location data for the mesh network. NSLocationWhenInUseUsageDescription We use your location to center maps of the mesh Privacy – Bluetooth Always Usage Description @@ -65,5 +82,27 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + UTImportedTypeDeclarations + + + UTTypeConformsTo + + public.data + + UTTypeDescription + MBTiles Map + UTTypeIconFiles + + UTTypeIdentifier + gvh.MeshtasticClient.mbtiles + UTTypeTagSpecification + + public.filename-extension + + mbtiles + + + + diff --git a/MeshtasticClient/MTAppDelegate.swift b/MeshtasticClient/MTAppDelegate.swift new file mode 100644 index 00000000..a59f9b27 --- /dev/null +++ b/MeshtasticClient/MTAppDelegate.swift @@ -0,0 +1,28 @@ +// +// AppDelegate.swift +// MeshtasticClient +// +// Created by Joshua Pirihi on 16/01/22. +// + +import Foundation +import UIKit + +class MTAppDelegate: NSObject, UIApplicationDelegate { + + func applicationDidFinishLaunching(_ application: UIApplication) { + } + + func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil + ) -> Bool { + // ... + return true + } + + func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { + print("We received a file") + return true + } +} diff --git a/MeshtasticClient/MeshtasticClientApp.swift b/MeshtasticClient/MeshtasticClientApp.swift index f7222a60..5f99066d 100644 --- a/MeshtasticClient/MeshtasticClientApp.swift +++ b/MeshtasticClient/MeshtasticClientApp.swift @@ -4,6 +4,8 @@ import CoreData @main struct MeshtasticClientApp: App { + @UIApplicationDelegateAdaptor var delegate: MTAppDelegate + let persistenceController = PersistenceController.shared @ObservedObject private var bleManager: BLEManager = BLEManager.shared diff --git a/MeshtasticClient/Views/Map/LocalMBTileOverlay.swift b/MeshtasticClient/Views/Map/LocalMBTileOverlay.swift new file mode 100644 index 00000000..2b967097 --- /dev/null +++ b/MeshtasticClient/Views/Map/LocalMBTileOverlay.swift @@ -0,0 +1,72 @@ +// +// LocalMBTileOverlay.swift +// MeshtasticClient +// +// Created by Joshua Pirihi on 16/01/22. +// + +import UIKit +import MapKit +import SQLite + +class LocalMBTileOverlay: MKTileOverlay { + + var path: String! + + var mb: Connection! + + init(mbTilePath path: String) { + + super.init(urlTemplate: nil) + self.path = path + + do { + self.mb = try Connection(self.path, readonly: true) + let metadata = Table("metadata") + + let name = Expression("name") + let value = Expression("value") + + let minZQuery = try mb.pluck(metadata.select(value).filter(name == "minzoom")) + self.minimumZ = Int(minZQuery![value])! + + let maxZQuery = try mb.pluck(metadata.select(value).filter(name == "maxzoom")) + self.maximumZ = Int(maxZQuery![value])! + + self.isGeometryFlipped = true + + //let boundingBoxString = try mb.pluck(metadata.select(value).filter(name == "bounds")) + //let boundCoords = boundingBoxString![value].split(separator: ",") + //self.boundingMapRect = MKMapRect(coordinates: [CLLocationCoordinate2D(latitude: Double(boundCoords[0]) ?? 0, longitude: Double(boundCoords[1]) ?? 0), CLLocationCoordinate2D(latitude: Double(boundCoords[2]) ?? 0, longitude: Double(boundCoords[3]) ?? 0)]) + + + } catch { + + } + + + } + + override func loadTile(at path: MKTileOverlayPath) async throws -> Data { + + let tileX = Int64(path.x) + let tileY = Int64(path.y) + let tileZ = Int64(path.z) + + let tileData = Expression("tile_data") + let zoomLevel = Expression("zoom_level") + let tileColumn = Expression("tile_column") + let tileRow = Expression("tile_row") + + if let dataQuery = try self.mb.pluck(Table("tiles").select(tileData).filter(zoomLevel == tileZ).filter(tileColumn == tileX).filter(tileRow == tileY)) { + + let data = Data(bytes: dataQuery[tileData].bytes, count: dataQuery[tileData].bytes.count)//dataQuery![tileData].bytes + + return data + + } else { + return Data() + } + } + +} diff --git a/MeshtasticClient/Views/Map/MapViewModule.swift b/MeshtasticClient/Views/Map/MapViewModule.swift index dddcc826..570da564 100644 --- a/MeshtasticClient/Views/Map/MapViewModule.swift +++ b/MeshtasticClient/Views/Map/MapViewModule.swift @@ -97,7 +97,7 @@ public struct MapView: UIViewRepresentable { //self.annotations = annotations - self.locationNodes = locationNodes + //self.locationNodes = locationNodes self.overlays = overlays @@ -135,22 +135,10 @@ public struct MapView: UIViewRepresentable { if self.customMapOverlay != self.presentCustomMapOverlayHash { mapView.removeOverlays(mapView.overlays) if let customMapOverlay = self.customMapOverlay { - let overlay = CustomMapOverlaySource( - parent: self, - mapName: customMapOverlay.mapName, - tileType: customMapOverlay.tileType, - defaultTile: customMapOverlay.defaultTile - ) - if let minZ = customMapOverlay.minimumZoomLevel { - overlay.minimumZ = minZ - } + let overlay = LocalMBTileOverlay(mbTilePath: Bundle.main.path(forResource: "offline_map", ofType: "mbtiles")!) - if let maxZ = customMapOverlay.maximumZoomLevel { - overlay.maximumZ = maxZ - } - - overlay.canReplaceMapContent = customMapOverlay.canReplaceMapContent + overlay.canReplaceMapContent = false//customMapOverlay.canReplaceMapContent mapView.addOverlay(overlay) } diff --git a/MeshtasticClient/Views/Nodes/NodeMap.swift b/MeshtasticClient/Views/Nodes/NodeMap.swift index b9cc26b1..280fb2d0 100644 --- a/MeshtasticClient/Views/Nodes/NodeMap.swift +++ b/MeshtasticClient/Views/Nodes/NodeMap.swift @@ -49,7 +49,7 @@ struct NodeMap: View { )*/ @State private var customMapOverlay: MapView.CustomMapOverlay? = MapView.CustomMapOverlay( - mapName: UserDefaults.standard.string(forKey: "meshMapCustomTileServer"), + mapName: "offlinemap", tileType: "png", canReplaceMapContent: true )