cuốn sách gpt4 ai đã làm

ios - 在 Swift 中共享位置

In lại Tác giả: Walker 123 更新时间:2023-11-29 05:17:35 26 4
mua khóa gpt4 Nike

我正在使用 Swift 语言开发 iOS 应用程序,我必须在启动屏幕中检查位置访问。在用户接受共享位置后,如何推送到另一个 View Controller ,否则显示以下警报以通知用户?

Please enable GPS in the Settings app

在splashScreen中我使用了这段代码:

let LocationMgr = LocationSingleton.sharedInstance //location
let status = CLLocationManager.authorizationStatus()

switch status {
// 1
case .notDetermined:
LocationMgr.locationManager!.requestWhenInUseAuthorization()
break
// 2
case .denied, .restricted:
let alert = UIAlertController(title: "Location Services disabled", message: "Please enable Location Services in Settings", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(okAction)

present(alert, animated: true, completion: nil)
break
case .authorizedAlways, .authorizedWhenInUse:
//I want to push to another view
break
}

// 4
LocationMgr.delegate = self
LocationMgr.startUpdatingLocation()

如何在用户选择(authorizedAlways,authorizedWhenInUse)后检查位置服务是否启用,然后推送到另一个 View ?

câu trả lời hay nhất

如果使用 Storyboard

在 Storyboard中,在初始屏幕和下一个屏幕之间创建一个 Segue。右键单击并从 Controller 图标拖动到下一个屏幕。和

create Segue

并输入标识符:

nhập mô tả hình ảnh ở đây

然后在你的 switch 语句中:

performSegue(withIdentifier: "showNextScreen", sender: nil)

关于ios - 在 Swift 中共享位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59017514/

26 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress