想知道某人是否对此有任何经验。因此,当用户点击添加到日历y上运行将事件添加到默认日历时,我有一个自定义通知操作集(AddTocalendar)。
怪异的行为是:
1-)如果应用不运行。它可以立即添加到日历上,远离推送通知,但是...
2-)如果应用程序已经在后台运行(未在前景中活跃),则不会添加到日历中,直到用户将应用程序放置在前景 - 活动。
为什么如果应用程序在后台运行,则不会从按下添加到日历?
这正在发生iOS 10.xx和iOS 11 ...
在进行一些调试和检查我与其他两个自定义操作中意识到的代码后,我曾在块外拨打pountaimionhandler()调用。
因此,首先,对于那些不知道的人,当您有自定义操作通知时,您对类别标识符进行检查,然后检查自定义操作标识符,然后处理任何您将要进行的操作,并且永远不会忘记拨打PloteInionHandler()紧随其后。
我的问题是,我正在使用带有块的函数的类服务,并在块之外使用完整的手服务。那就是为什么它做到了这种怪异的行为。
这是完整的正确代码并显示错误在哪里...
// AppDelegate.swif
// Handling notifications - When in background
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
// Notifcation Category: Reserve
if response.notification.request.content.categoryIdentifier == "RESERVE" {
// Handle the actions for the reserve
// Action: Approve
if response.actionIdentifier == "APPROVE" {
// The user launched the app
print("Approve")
// print(response.notification.request.content.userInfo)
print(response.notification.request.content.userInfo.description)
print(response.notification.request.content)
if let info = response.notification.request.content.userInfo as? Dictionary<AnyHashable,Any> {
// Check if value present before using it
let reserveid = info["reserveid"] as? String ?? ""
let fecha = info["fecha"] as? String ?? ""
let username = info["username"] as? String ?? ""
let qty = info["qty"] as? String ?? ""
let comentario = info["comentario"] as? String ?? ""
let approval = info["approval"] as? String ?? ""
let empresa_nombre = info["empresanombre"] as? String ?? ""
let direccion = info["direccion"] as? String ?? ""
let lat = info["lat"] as? String ?? ""
let long = info["long"] as? String ?? ""
let telefono = info["tel"] as? String ?? ""
let provincia = info["prov"] as? String ?? ""
let reserveService = ReserveService()
reserveService.process(id: reserveid, approve: true, completion: { (success) in
if (success) {
let note = "(empresa_nombre)n(direccion) - (provincia)nnReserva de: (username)nCantidad de personas: (qty)nFecha: (fecha)nComentario de cliente: (comentario)"
print(note)
let EventServices = EventService.sharedInstance
EventServices.startDate = "(fecha)"
EventServices.title = "Reserva de (username)"
EventServices.notes = note
EventServices.isRestadmin = true
EventServices.lat = lat
EventServices.long = long
EventServices.direccion = direccion
EventServices.provincia = provincia
EventServices.emp_nombre = empresa_nombre
EventServices.checkCalendarAuthorizationStatusAndAdd()
completionHandler() // correct completionHandler Call
}
})
}
// completionHandler() // had it here mistakenly.
}
}
}