2

我正在构建一个使用对位置敏感的本地通知的应用程序。即使应用程序在后台,我也希望这些触发。我能够让它在模拟器中工作,但不是设备。他们在设备上开火,但只在前台开火。

这是我的设置方式:

        let trigger = UNLocationNotificationTrigger(region:region, repeats:true)
        let delete = UNNotificationAction(identifier: "DeleteAction",
                                                title: "Delete", options: [.destructive])
        let category = UNNotificationCategory(identifier: “testcategory”, actions: [delete], intentIdentifiers: [], options: [])
        center.setNotificationCategories([category])
        let content = UNMutableNotificationContent()
        content.title = “This is a test“
        content.body = "You're at your destination"
        content.sound = UNNotificationSound.default()
        content.categoryIdentifier = “testcategory”
        let identifier = "testnotif"
        let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
            center.add(request, withCompletionHandler: { (error) in
                if let error = error {
                    print(error)
                } else {
                    //successful
                }
            })
4

0 回答 0