iOS app running.

Map API key needs to be set in untracked file Config.local.xcconfig
Still issues with showing map
This commit is contained in:
Olof Hedman
2025-10-02 18:06:43 +02:00
parent cc4a99effb
commit 72d9b879c4
10 changed files with 168 additions and 27 deletions

3
.gitignore vendored
View File

@@ -21,4 +21,5 @@ google-services.json
.kotlin/ .kotlin/
# KMP/Gradle build outputs # KMP/Gradle build outputs
**/build/ **/build/
# iOS secrets
ios/Klottr/Klottr/Config.local.xcconfig

View File

@@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
412CF4A32E719E7D00EADB15 /* shared.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 412CF4A22E719E7D00EADB15 /* shared.xcframework */; }; 412CF4A32E719E7D00EADB15 /* shared.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 412CF4A22E719E7D00EADB15 /* shared.xcframework */; };
412CF4B12E71B7C300EADB15 /* GoogleSignIn in Frameworks */ = {isa = PBXBuildFile; productRef = 412CF4B02E71B7C300EADB15 /* GoogleSignIn */; }; 412CF4B12E71B7C300EADB15 /* GoogleSignIn in Frameworks */ = {isa = PBXBuildFile; productRef = 412CF4B02E71B7C300EADB15 /* GoogleSignIn */; };
414EDCB22E8E6E730024FBE0 /* libsqlite3.0.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 414EDCB12E8E6E2B0024FBE0 /* libsqlite3.0.tbd */; };
414EDCB52E8E76260024FBE0 /* GoogleMaps in Frameworks */ = {isa = PBXBuildFile; productRef = 414EDCB42E8E76260024FBE0 /* GoogleMaps */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@@ -33,6 +35,8 @@
412CF4582E7037D800EADB15 /* KlottrTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KlottrTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 412CF4582E7037D800EADB15 /* KlottrTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KlottrTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
412CF4622E7037D800EADB15 /* KlottrUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KlottrUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 412CF4622E7037D800EADB15 /* KlottrUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KlottrUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
412CF4A22E719E7D00EADB15 /* shared.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = shared.xcframework; path = "/Users/olle/Documents/git-personal/klottr/shared/build/XCFrameworks/release/shared.xcframework"; sourceTree = "<absolute>"; }; 412CF4A22E719E7D00EADB15 /* shared.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = shared.xcframework; path = "/Users/olle/Documents/git-personal/klottr/shared/build/XCFrameworks/release/shared.xcframework"; sourceTree = "<absolute>"; };
414EDCB02E8E6E140024FBE0 /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; };
414EDCB12E8E6E2B0024FBE0 /* libsqlite3.0.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.0.tbd; path = usr/lib/libsqlite3.0.tbd; sourceTree = SDKROOT; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */ /* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
@@ -71,6 +75,8 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
414EDCB52E8E76260024FBE0 /* GoogleMaps in Frameworks */,
414EDCB22E8E6E730024FBE0 /* libsqlite3.0.tbd in Frameworks */,
412CF4A32E719E7D00EADB15 /* shared.xcframework in Frameworks */, 412CF4A32E719E7D00EADB15 /* shared.xcframework in Frameworks */,
412CF4B12E71B7C300EADB15 /* GoogleSignIn in Frameworks */, 412CF4B12E71B7C300EADB15 /* GoogleSignIn in Frameworks */,
); );
@@ -118,6 +124,8 @@
412CF4AF2E71B7C300EADB15 /* Frameworks */ = { 412CF4AF2E71B7C300EADB15 /* Frameworks */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
414EDCB12E8E6E2B0024FBE0 /* libsqlite3.0.tbd */,
414EDCB02E8E6E140024FBE0 /* libsqlite3.tbd */,
); );
name = Frameworks; name = Frameworks;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -143,6 +151,7 @@
name = Klottr; name = Klottr;
packageProductDependencies = ( packageProductDependencies = (
412CF4B02E71B7C300EADB15 /* GoogleSignIn */, 412CF4B02E71B7C300EADB15 /* GoogleSignIn */,
414EDCB42E8E76260024FBE0 /* GoogleMaps */,
); );
productName = Klottr; productName = Klottr;
productReference = 412CF4482E7037D700EADB15 /* Klottr.app */; productReference = 412CF4482E7037D700EADB15 /* Klottr.app */;
@@ -228,6 +237,7 @@
minimizedProjectReferenceProxies = 1; minimizedProjectReferenceProxies = 1;
packageReferences = ( packageReferences = (
412CF4A62E71AF4C00EADB15 /* XCRemoteSwiftPackageReference "GoogleSignIn-iOS" */, 412CF4A62E71AF4C00EADB15 /* XCRemoteSwiftPackageReference "GoogleSignIn-iOS" */,
414EDCB32E8E76260024FBE0 /* XCRemoteSwiftPackageReference "ios-maps-sdk" */,
); );
preferredProjectObjectVersion = 77; preferredProjectObjectVersion = 77;
productRefGroup = 412CF4492E7037D700EADB15 /* Products */; productRefGroup = 412CF4492E7037D700EADB15 /* Products */;
@@ -424,6 +434,8 @@
}; };
412CF46D2E7037D800EADB15 /* Debug */ = { 412CF46D2E7037D800EADB15 /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
baseConfigurationReferenceAnchor = 412CF44A2E7037D700EADB15 /* Klottr */;
baseConfigurationReferenceRelativePath = Config.xcconfig;
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
@@ -435,6 +447,7 @@
FRAMEWORK_SEARCH_PATHS = ""; FRAMEWORK_SEARCH_PATHS = "";
GENERATE_INFOPLIST_FILE = NO; GENERATE_INFOPLIST_FILE = NO;
INFOPLIST_FILE = Klottr/Info.plist; INFOPLIST_FILE = Klottr/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Klottr;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = NO; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = NO;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES;
@@ -455,6 +468,8 @@
}; };
412CF46E2E7037D800EADB15 /* Release */ = { 412CF46E2E7037D800EADB15 /* Release */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
baseConfigurationReferenceAnchor = 412CF44A2E7037D700EADB15 /* Klottr */;
baseConfigurationReferenceRelativePath = Config.xcconfig;
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
@@ -466,6 +481,7 @@
FRAMEWORK_SEARCH_PATHS = ""; FRAMEWORK_SEARCH_PATHS = "";
GENERATE_INFOPLIST_FILE = NO; GENERATE_INFOPLIST_FILE = NO;
INFOPLIST_FILE = Klottr/Info.plist; INFOPLIST_FILE = Klottr/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Klottr;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = NO; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = NO;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES;
@@ -606,6 +622,14 @@
minimumVersion = 9.0.0; minimumVersion = 9.0.0;
}; };
}; };
414EDCB32E8E76260024FBE0 /* XCRemoteSwiftPackageReference "ios-maps-sdk" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/googlemaps/ios-maps-sdk";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 10.3.0;
};
};
/* End XCRemoteSwiftPackageReference section */ /* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */ /* Begin XCSwiftPackageProductDependency section */
@@ -614,6 +638,11 @@
package = 412CF4A62E71AF4C00EADB15 /* XCRemoteSwiftPackageReference "GoogleSignIn-iOS" */; package = 412CF4A62E71AF4C00EADB15 /* XCRemoteSwiftPackageReference "GoogleSignIn-iOS" */;
productName = GoogleSignIn; productName = GoogleSignIn;
}; };
414EDCB42E8E76260024FBE0 /* GoogleMaps */ = {
isa = XCSwiftPackageProductDependency;
package = 414EDCB32E8E76260024FBE0 /* XCRemoteSwiftPackageReference "ios-maps-sdk" */;
productName = GoogleMaps;
};
/* End XCSwiftPackageProductDependency section */ /* End XCSwiftPackageProductDependency section */
}; };
rootObject = 412CF4402E7037D600EADB15 /* Project object */; rootObject = 412CF4402E7037D600EADB15 /* Project object */;

View File

@@ -1,5 +1,5 @@
{ {
"originHash" : "68aa00e3cba36db2e0a76f54dbc84d1f079d8aa9a19bfa9fce02d6286bd620b7", "originHash" : "a121837d5658eb88623237b7d13ceb8badf03b05874b782ea35b621e17a6ec31",
"pins" : [ "pins" : [
{ {
"identity" : "app-check", "identity" : "app-check",
@@ -55,6 +55,15 @@
"version" : "5.0.0" "version" : "5.0.0"
} }
}, },
{
"identity" : "ios-maps-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/googlemaps/ios-maps-sdk",
"state" : {
"revision" : "eae9fb0930f6f8ebcc5bfa6f7683da3cc3782cc3",
"version" : "10.3.0"
}
},
{ {
"identity" : "promises", "identity" : "promises",
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",

View File

@@ -9,6 +9,7 @@
// iosApp/AppDelegate.swift // iosApp/AppDelegate.swift
import UIKit import UIKit
import GoogleSignIn import GoogleSignIn
import GoogleMaps
import shared import shared
@main @main
@@ -17,6 +18,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if let key = Bundle.main.object(forInfoDictionaryKey: "GMSApiKey") as? String,
!key.isEmpty {
GMSServices.provideAPIKey(key)
} else {
assertionFailure("Missing GMSApiKey. Check Config.local.xcconfig and Info.plist wiring.")
}
PlatformAuthStorage.shared.install(delegate: KeychainStorage()) PlatformAuthStorage.shared.install(delegate: KeychainStorage())
return true return true
} }

View File

@@ -0,0 +1 @@
#include? "Config.local.xcconfig"

View File

@@ -14,6 +14,8 @@
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string> <string>$(MARKETING_VERSION)</string>
<key>GMSApiKey</key>
<string>$(GMS_API_KEY)</string>
<key>CFBundleURLTypes</key> <key>CFBundleURLTypes</key>
<array> <array>
<dict> <dict>
@@ -29,17 +31,13 @@
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string> <string>$(CURRENT_PROJECT_VERSION)</string>
<key>UILaunchScreen</key> <key>UILaunchScreen</key>
<dict> <dict>
<!-- Optional image in your asset catalog --> <key>UIColorName</key>
<!-- <key>UIImageName</key><string>LaunchScreenLogo</string> --> <string>LaunchScreenBackground</string>
<!-- Solid background from a Color Set named LaunchScreenBackground --> <key>UIImageRespectsSafeAreaInsets</key>
<key>UIColorName</key><string>LaunchScreenBackground</string> <true/>
<!-- Safe default -->
<key>UIImageRespectsSafeAreaInsets</key><true/>
</dict> </dict>
<key>GIDClientID</key> <key>GIDClientID</key>
<string>508890452239-66lqrsbphlmqltb6aoe3c0d6dlgtjse8.apps.googleusercontent.com</string> <string>508890452239-66lqrsbphlmqltb6aoe3c0d6dlgtjse8.apps.googleusercontent.com</string>
<key>GIDServerClientID</key> <key>GIDServerClientID</key>
@@ -61,6 +59,8 @@
</array> </array>
</dict> </dict>
</dict> </dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Platstillstånd behövs för att hitta klotter och använda kartan</string>
<key>UISupportedInterfaceOrientations</key> <key>UISupportedInterfaceOrientations</key>
<array> <array>
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>

View File

@@ -8,31 +8,112 @@
import UIKit import UIKit
import shared import shared
import UserNotifications
import CoreLocation
class SceneDelegate: UIResponder, UIWindowSceneDelegate { class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow? var window: UIWindow?
private lazy var locationManager: CLLocationManager = {
let m = CLLocationManager()
m.delegate = self
return m
}()
func scene(_ scene: UIScene, func scene(_ scene: UIScene,
willConnectTo session: UISceneSession, willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) { options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = scene as? UIWindowScene else { return } guard let windowScene = scene as? UIWindowScene else { return }
let root = MainKt.MainViewController() // Compose VC var rootVC: UIViewController! // will be set below
rootVC = MainKt.MainViewController(
onRequestPerms: { [weak self] in
self?.requestAppPermissions()
},
onLogin: { [weak self] in
guard let presenting = rootVC else { return }
Task {
do {
try await GoogleAuthIOS.signIn(presenting: presenting)
} catch {
NSLog("Sign In Error: \(error)")
}
}
},
onLogout: {
GoogleAuthIOS.signOut()
}
)
let window = UIWindow(windowScene: windowScene) let window = UIWindow(windowScene: windowScene)
window.rootViewController = root window.rootViewController = rootVC
self.window = window self.window = window
window.makeKeyAndVisible() window.makeKeyAndVisible()
// If you need to kick off sign-in at launch, do it here:
DispatchQueue.main.async { DispatchQueue.main.async {
Task { Task {
do { await GoogleAuthIOS.restorePreviousSignIn()
try await GoogleAuthIOS.signIn(presenting: root)
} catch {
NSLog("Sign In Error: \(error)")
}
} }
} }
} }
private func requestAppPermissions() {
requestAlertPermission { [weak self] granted in
NSLog("Alerts granted: \(granted)")
// Chain location after alerts, or call independently as needed:
self?.requestLocationPermission()
}
}
private func requestAlertPermission(completion: @escaping (Bool) -> Void) {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
if let error = error { NSLog("Alert permission error: \(error)") }
DispatchQueue.main.async { completion(granted) }
}
// If you also need push notifications, you'll later call:
// UIApplication.shared.registerForRemoteNotifications()
}
private func requestLocationPermission() {
// Configure accuracy if needed
if #available(iOS 14.0, *) {
locationManager.desiredAccuracy = kCLLocationAccuracyBest
}
// Request foreground location permission. Use requestAlwaysAuthorization() only if you need background updates.
locationManager.requestWhenInUseAuthorization()
// Optionally start a one-off location update to prompt the system UI:
locationManager.requestLocation()
}
}
// MARK: - CLLocationManagerDelegate
extension SceneDelegate: CLLocationManagerDelegate {
// iOS 14+
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
logAuthStatus(manager)
}
// iOS 13 and earlier
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
logAuthStatus(manager)
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
NSLog("Location: didUpdateLocations \(locations)")
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: any Error) {
NSLog("Location: didFailWithError \(error.localizedDescription)")
}
private func logAuthStatus(_ manager: CLLocationManager) {
let status = manager.authorizationStatus
switch status {
case .authorizedWhenInUse: NSLog("Location: authorizedWhenInUse")
case .authorizedAlways: NSLog("Location: authorizedAlways")
case .denied: NSLog("Location: denied")
case .restricted: NSLog("Location: restricted")
case .notDetermined: NSLog("Location: notDetermined")
@unknown default: NSLog("Location: unknown")
}
}
} }

View File

@@ -3,5 +3,15 @@ package app.klottr
import androidx.compose.ui.window.ComposeUIViewController import androidx.compose.ui.window.ComposeUIViewController
import platform.UIKit.UIViewController import platform.UIKit.UIViewController
fun MainViewController(): UIViewController = fun MainViewController(
ComposeUIViewController { KlottrRoot() } onRequestPerms: () -> Unit = {},
onLogin: () -> Unit = {},
onLogout: () -> Unit = {},
): UIViewController =
ComposeUIViewController {
KlottrAppShell(
onRequestPerms = onRequestPerms,
onLogin = onLogin,
onLogout = onLogout
)
}

View File

@@ -18,8 +18,11 @@ actual object KLog {
private fun log(level: String, tag: String?, text: () -> String) { private fun log(level: String, tag: String?, text: () -> String) {
if (!enabled) return if (!enabled) return
val tg = tagOrDefault(tag) val tg = tagOrDefault(tag)
// %@ konverterar Kotlin String -> NSString // Build string in kotlin
NSLog("[$level][%@] %@", tg, text()) val msg = "[$level][$tg] ${text()}"
// Pass a single argument to avoid C-varargs issues
val safe = msg.replace("%", "%%") // prevent accidental format parsing
NSLog(safe)
} }
actual fun d(tag: String?, msg: () -> String) = log("D", tag, msg) actual fun d(tag: String?, msg: () -> String) = log("D", tag, msg)
@@ -29,10 +32,10 @@ actual object KLog {
actual fun e(tag: String?, t: Throwable?, msg: () -> String) { actual fun e(tag: String?, t: Throwable?, msg: () -> String) {
if (!enabled) return if (!enabled) return
val tg = tagOrDefault(tag) val tg = tagOrDefault(tag)
if (t != null) { val base = "[E][$tg] ${msg()}"
NSLog("[E][%@] %@ — %@", tg, msg(), t.stackTraceToString()) val full = if (t != null) "$base — ${t.stackTraceToString()}" else base
} else {
NSLog("[E][%@] %@", tg, msg()) val safe = full.replace("%", "%%") // prevent accidental format parsing
} NSLog(safe)
} }
} }