Hello everyone,
I'm encountering a strange location authorization issue in the iOS simulator, and I'm hoping someone can help me analyze it.
Problem Description:
When my app runs for the first time in the simulator, it requests location permissions.
I select "Deny" for the authorization.
Then, I go to the simulator's "Settings" -> "Privacy & Security" -> "Location Services" and enable location permissions for my app.
However, when I return to the app, CLLocationManager.authorizationStatus still returns .notDetermined, and the authorization request pop-up does not appear again.
This issue persists even after resetting the simulator settings multiple times.
import CoreLocation
@Observable
final class LocationManager: NSObject, CLLocationManagerDelegate {
var locationManager = CLLocationManager()
var currentLocation: CLLocationCoordinate2D?
override init() {
super.init()
locationManager.delegate = self
}
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
let status = manager.authorizationStatus
print("Authorize Status: \(status)")
switch status {
case .authorizedWhenInUse, .authorizedAlways:
locationManager.startUpdatingLocation()
case .denied, .restricted:
stopLocation()
case .notDetermined:
locationManager.requestWhenInUseAuthorization()
print("Location permission not determined.")
@unknown default:
break
}
}
func requestLocation() {
let status = locationManager.authorizationStatus
if status == .authorizedWhenInUse || status == .authorizedAlways {
locationManager.requestLocation()
} else {
locationManager.requestWhenInUseAuthorization()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let newLocation = locations.first else { return }
currentLocation = newLocation.coordinate
print("Updated location: \(newLocation.coordinate)")
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("Location update failed with error: \(error.localizedDescription)")
currentLocation = nil
}
func stopLocation() {
locationManager.stopUpdatingLocation()
print("Stopped updating location")
}
}
Post
Replies
Boosts
Views
Activity
I’m currently working on a SwiftUI project and trying to implement a transition effect similar to ZoomTransitions. However, I’ve run into an issue.
When transitioning from Page A to Page B using .navigationTransition(.zoom(sourceID: "world", in: animation)), Page A shrinks as expected, but its background color changes to the default white instead of the color I preset.
I want the background color of Page A to remain consistent with my preset during the entire transition process. Here’s a simplified version of my code:
Page A
PartnerCard()
.matchedTransitionSource(id: item.id, in: animation)
Page B
``.navigationTransition(.zoom(sourceID: "world", in: animation))
Why are asynchronous tasks not executed in Xcode Canvas, and why do they only work in the simulator?
Hi everyone, I'm new to Xcode and iOS development. I've encountered an issue where asynchronous tasks seem to not execute in Xcode Canvas, but they work fine in the simulator. Can anyone explain why this might be happening or what I could do to fix it? Thank you for your help!
struct PartnerProfileView: View {
@State private var showSheet: Bool = true
let partnerName: String
var body: some View {
ZStack(alignment: .bottom) {
Color("EFEFF4_0F2534")
ScrollView(showsIndicators: false) {
headerSection()
infoSection()
.padding(.bottom, 5)
sectionTitle("Other Skills")
skillsGrid()
sectionTitle("···")
dynamicsSection()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
CustomTabBar()
}
.navigationBarHidden(true)
.ignoresSafeArea(edges: .all)
.onAppear {
print("PartnerProfileView received")
Task {
await BottomCustomPopup().present()
}
}
.onChange(of: showSheet) { oldState, newValue in
print("oldState \(oldState)")
print("newValue \(newValue)")
}
}
}
//@MainActor
struct BottomCustomPopup: BottomPopup {
var body: some View {
HStack(spacing: 0) {
Text("Hello World")
Spacer()
Button(action: { Task { await dismissLastPopup() }}) { Text("Dismiss") }
}
.padding(.vertical, 20)
.padding(.leading, 24)
.padding(.trailing, 16)
}
}