我们能否仅在iOS中的特定视图控制器中安排UnuseNotificationCenter?
我只想在特定的页面中显示通知,比如从通知的有效负载获得的userid不等于当前的userid。我应该在appdelegate中的何处使用此条件?我使用了我们能否仅在iOS中的特定视图控制器中安排UnuseNotificationCenter?,ios,swift,push-notification,unusernotificationcenter,Ios,Swift,Push Notification,Unusernotificationcenter,我只想在特定的页面中显示通知,比如从通知的有效负载获得的userid不等于当前的userid。我应该在appdelegate中的何处使用此条件?我使用了userNotificationCenter的willPresent委托在应用程序位于前台时发送通知,并请求在AppDelegate的didfishlauchingWithOptions中显示通知方法的权限 willPresent方法的示例代码如下所示 func userNotificationCenter(_ center: UNUserNot
userNotificationCenter
的willPresent委托在应用程序位于前台时发送通知,并请求在AppDelegate
的didfishlauchingWithOptions
中显示通知方法的权限
willPresent方法的示例代码如下所示
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void){
if let userID = notification.request.content.userInfo["user_id"] {
self.userIDSelected = userID as! String
}
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.removeAllDeliveredNotifications()
if self.currentuserID != self.userIDSelected
{
completionHandler([.alert,.badge,.sound])
}
else
{
completionHandler([])
}
}