【发布时间】:2018-08-20 05:41:36
【问题描述】:
我是第一次处理交互式推送通知。我遇到了单击操作按钮的问题。我已经使用代码创建了推送通知。
let acceptAction = UIMutableUserNotificationAction()
acceptAction.identifier = "ACCEPT_REQUEST"
acceptAction.title = "Accept"
acceptAction.activationMode = .background
acceptAction.isAuthenticationRequired = true
acceptAction.isDestructive = false
// Reject Action
let rejectAction = UIMutableUserNotificationAction()
rejectAction.identifier = "REJECT_REQUEST"
rejectAction.title = "Reject"
rejectAction.activationMode = .background
rejectAction.isAuthenticationRequired = true
rejectAction.isDestructive = false
let requestCategory = UIMutableUserNotificationCategory()
requestCategory.identifier = "CONNECTION_REQUEST"
let categoriesForSettings = NSSet(array: [requestCategory,clubRequestCategory,groupRequestCategory,referralCategory])//NSSet(objects: requestCategory)
// Register the notification settings.
let types:UIUserNotificationType = [.alert, .badge, .sound]
let newNotificationSettings =
UIUserNotificationSettings(types: types, categories: categoriesForSettings as! Set<UIUserNotificationCategory>)
UIApplication.shared.registerUserNotificationSettings(newNotificationSettings)
这是我为处理推送操作编写的代码。
func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [AnyHashable : Any], completionHandler: @escaping () -> Void) {
if(identifier == "ACCEPT_REQUEST" || identifier == "REJECT_REQUEST")
{
// API Call goes here
}
}
我尝试调试代码,我看到用 API 函数编写的日志已打印,但它没有到达服务器。如果我从后台 API 调用成功启动应用程序并且还从服务器获得响应。我将 Alamofire 用于 API 相关的东西。
谁能帮我摆脱困境?
如果有人需要更多详细信息,请告诉我。
【问题讨论】:
标签: ios swift push-notification apple-push-notifications