gpt4 book ai didi

ios - 从类型 '(_) throws -> Void' 的抛出函数到非抛出函数类型的无效转换 '([UNNotificationRequest]) -> Void

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

我正在尝试获取有关本地通知的待处理通知请求。它抛出我的错误:“从'(_) throws -> Void'类型的抛出函数到非抛出函数类型'([UNNotificationRequest]) -> Void'的无效转换”

我的代码是:

var notificationTitle = "\(String(describing: notificationData!["title"]))"
var notificationInterval: Int = notificationData!["interval"] as! Int
let center = UNUserNotificationCenter.current()
center.getPendingNotificationRequests(completionHandler: {(requests) -> Void in
var notificationExist:Bool = false
for notificationRequest in requests {
try{
var notificationContent:UNNotificationContent = notificationRequest.content
}
}

最佳答案

你可能想这样做,

    center.getPendingNotificationRequests(completionHandler: {requests -> () in
var notificationExist:Bool = false
for notificationRequest in requests {
do {
var notificationContent:UNNotificationContent = try notificationRequest.content
}
catch {
print(error)
}
}
}

关于ios - 从类型 '(_) throws -> Void' 的抛出函数到非抛出函数类型的无效转换 '([UNNotificationRequest]) -> Void,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50128723/

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