gpt4 book ai didi

ios - 从另一种方法获取区域标识符?

转载 作者:行者123 更新时间:2023-11-28 08:11:35 25 4
gpt4 key购买 nike

我正在尝试做基于位置的项目。当我收到通知时,我将按"is"按钮并转到应用程序中的地点页面。要执行此过程,我应该采用通知标题,但我正在核心位置的 didenterregion 方法中创建通知。对于通知操作,我应该使用 didreceiveresponse 方法。我如何获取来自 didenterregion 的通知标题以用于 diredreceiveresponse 方法?

这是我的代码

  UNUserNotificationCenter.current().requestAuthorization(
options: [.alert,.sound,.badge],
completionHandler: { (didAllow,error) in


}
)

let answerYes = UNNotificationAction(identifier: "answerYes", title: "Evet", options: UNNotificationActionOptions.foreground)
let answerCancel = UNNotificationAction(identifier: "answerCancel", title: "İptal", options: UNNotificationActionOptions.foreground)

let category = UNNotificationCategory(identifier: "myCategory", actions: [answerYes,answerCancel], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([category])
let topkapiLatitude: CLLocationDegrees = 41.013
let topkapiLongitude: CLLocationDegrees = 28.984
let topkapiCenter: CLLocationCoordinate2D = CLLocationCoordinate2DMake(topkapiLatitude, topkapiLongitude)
let topkapiRadius: CLLocationDistance = CLLocationDistance(100.0)
let topkapiIdentifier: String = "Topkapı Sarayı"

let topkapiRegion = CLCircularRegion(center: topkapiCenter, radius: topkapiRadius, identifier: topkapiIdentifier)

let yrbtnLatitude: CLLocationDegrees = 41.0081
let yrbtnLongitude: CLLocationDegrees = 28.9778
let yrbtnCenter: CLLocationCoordinate2D = CLLocationCoordinate2DMake(yrbtnLatitude, yrbtnLongitude)
let yrbtnRadius: CLLocationDistance = CLLocationDistance(100.0)
let yrbtnIdentifier: String = "Yerebatan Sarnıcı"

let yrbtnRegion = CLCircularRegion(center: yrbtnCenter, radius: yrbtnRadius, identifier: yrbtnIdentifier)

locationManager.distanceFilter = 10
locationManager.desiredAccuracy = kCLLocationAccuracyBest
topkapiRegion.notifyOnEntry = true
yrbtnRegion.notifyOnEntry = true

locationManager.delegate=self
UNUserNotificationCenter.current().delegate = self
locationManager.requestAlwaysAuthorization()
locationManager.startMonitoring(for: topkapiRegion)
locationManager.startMonitoring(for: yrbtnRegion)
locationManager.startUpdatingLocation()

return true
}


func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if response.actionIdentifier == "answerYes" {

}
else {

}
}

func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {

let content = UNMutableNotificationContent()
content.title = region.identifier
content.subtitle = "You are at \(region.identifier) now"
content.body = "Do you want to learn history of this place?"
content.badge = 1
content.categoryIdentifier = "myCategory"


let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 2, repeats: false)
let request = UNNotificationRequest(identifier: "timerDone", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)








}

最佳答案

您可以通过 UNMutableNotificationContent 的 userInfo 属性自定义对象。

content.userInfo = ["yourkey": "Your object"] as [String : Any] // set in region method

然后进入** didReceive**

print(response.notification.request.content.userInfo) // this is your data

关于ios - 从另一种方法获取区域标识符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43622531/

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