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

Ozge Shura HIZAL

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

这是我的代码

  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)








    }
KKRocks

您可以通过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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Dart(Flutter)中从一种方法获取值到另一种方法

在jsfuck中获取“ C”字母的另一种方法

SPRING MVC:一种方法中定义的HttpSession对另一种方法不可用

找出一种方法是否可以调用另一种方法

在Laravel 5.2中如何在一种方法中设置会话并在另一种方法中获取会话数据

有没有一种方法可以将关键字用作枚举中的标识符?

有没有一种方法可以自动在R Markdown中向图像添加标识符?

有一种方法可以从另一种方法的生成器中获取下一个值吗?

IntelliJ检查一种方法可以从另一种方法访问

防止在另一种方法中使用一种方法

过滤方法上另一种方法?

有没有一种方法来获取Azure AD用户的成对标识符

从另一种方法检索到的一种方法中设置的属性返回null

用JavaScript编写三元运算符的另一种方法

terraform计划是一种方法,但不是另一种方法?

日食自动获取和设置方法的另一种方法

无法将一种方法调用到另一种方法

通过另一种方法获取方法的局部变量

调用get方法的另一种方法

使用 List 从一种方法到另一种方法

在 Python 中从另一种方法调用一种方法

如何从一种方法获取变量到另一种方法?如何从假设到 void add() 中获取 int x?

从承诺中返回数据并在另一种方法中获取它

从文件读取时尝试以另一种方法从数组中获取最大值

如何将一种方法中的变量用于另一种方法?

在 Python 中从一种方法调用变量到另一种方法

NestJS - 从 POST 请求中获取响应正文并以另一种方法将其保存到 mongoDB

在 Python 中的另一种方法中使用一种方法中的变量

Django Rest Framework 如何从一种方法调用另一种方法中的变量?