gpt4 book ai didi

swift - 为什么确认窗口在 viewDidLoad 中消失了?

转载 作者:可可西里 更新时间:2023-11-01 01:06:56 25 4
gpt4 key购买 nike

尝试获取用户的位置。确认窗口出现 1 秒后立即消失

import UIKit
import MapKit
import CoreLocation

class NearbyViewController: UIViewController, CLLocationManagerDelegate {

override func viewDidLoad() {
super.viewDidLoad()
let locationManager = CLLocationManager()
locationManager.requestWhenInUseAuthorization()
}

}

最佳答案

制作

let locationManager = CLLocationManager()

实例变量

class ViewController: UIViewController, CLLocationManagerDelegate {
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.requestWhenInUseAuthorization()
}
}

因为它在 viewDidLoad 的末尾被释放,它会自动隐藏警报

关于swift - 为什么确认窗口在 viewDidLoad 中消失了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57677175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com