gpt4 book ai didi

ios - 当他输入 CLLocation 时如何通知用户?

转载 作者:搜寻专家 更新时间:2023-11-01 06:38:12 24 4
gpt4 key购买 nike

情况:

我遵循了以下教程:

https://www.raywenderlich.com/95014/geofencing-ios-swift


问题:

以下函数永远不会被触发:

AppDelegate.swift

func locationManager(manager: CLLocationManager, didEnterRegion region: CLRegion) {
if region is CLCircularRegion {
handleRegionEvent(region)
}
}

func locationManager(manager: CLLocationManager, didExitRegion region: CLRegion) {
if region is CLCircularRegion {
handleRegionEvent(region)
}
}

func handleRegionEvent(region: CLRegion!) {

print("Geofence triggered!")

// Show an alert if application is active
if UIApplication.sharedApplication().applicationState == .Active {
if let message = notefromRegionIdentifier(region.identifier) {
if let viewController = window?.rootViewController {
showSimpleAlertWithTitle("Congratulations", message: "You just found: " + message , viewController: viewController)
}
}
} else {
// Otherwise present a local notification
let notification = UILocalNotification()
notification.alertBody = "You just found: " + notefromRegionIdentifier(region.identifier)!

notification.soundName = "Default";
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
}
}

问题:

本教程是为 iOS 8 编写的。我目前使用的是 iOS 9.3。您认为是什么原因导致了这个问题,我该如何解决?

最佳答案

您没有显示用于设置 CL 的代码 - 这可能是您的问题所在。

您是否编辑了 info.plist?

您是在请求许可吗?

您是否调用了 CL 管理器上的启动函数之一?

关于ios - 当他输入 CLLocation 时如何通知用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38960160/

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