Die Funktion UNUserNotificationCenter wird nicht beim Klicken aufgerufen Aktion Schaltfläche Chat in Benachrichtigung nach 3D Berühren, wenn App nicht aktiv ist (nicht einmal im Hintergrund oder sagen wurde beendet). Ich verwendete "anhängen, um nach Namen zu verarbeiten" in Xcode, um App zu debuggen, als App beendet wurde. Hier ist der Code:UNUserNotificationCenter didRecieve Antwort wird nicht aufgerufen, wenn App beendet wird
import UIKit
import Mixpanel
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
//setup mixpanel
self.handlePushNotificationWithUserInfo(launchOptions: launchOptions)
//ask for push notification perms
return true
}
Wenn Benachrichtigung Pop-up (Sent von MixPanel) diese Funktion zuerst genannt wird,
Anruf 1:
func handlePushNotificationWithUserInfo(launchOptions: [NSObject: AnyObject]?) {
//Handle PushNotification when app is opened
}
dann es hier geht,
Anruf 2:
//register for notification
func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
// Enable or disable features based on authorization.
}
center.delegate = self
let actionChat = UNNotificationAction(identifier: Constants.ActionType.CHAT.rawValue, title: "Chat", options: [.foreground])
let categoryOptions = UNNotificationCategoryOptions(rawValue: 0)
let customerSupportCategory = UNNotificationCategory(identifier: Constants.NotificationType.CUSTOMER_SUPPORT.rawValue, actions: [actionChat], intentIdentifiers: [], options: categoryOptions)
center.setNotificationCategories([customerSupportCategory])
}
application.registerForRemoteNotifications()
}
Anruf 3:
// remote notification
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
....Some Code....
}
Aber unten Funktion wird nicht genannt. Aber wenn App im Hintergrund läuft dann unter Funktion aufgerufen wird und funktioniert alles gut OTHERWISE App kommt in den Vordergrund und Chat danach nicht.
// action buttons in enhanced Notification
@available(iOS 10, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler:() -> Void) {
guard let action = Constants.ActionType(rawValue: response.actionIdentifier) else {
completionHandler()
return
}
switch action {
case .CHAT:
_ = self.handleRemoteUrl(NSURL(string: "chat") as? URL)
default:
_ = self.handleRemoteUrl(NSURL(string: "chat") as? URL)
}
completionHandler()
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .sound])
}
}
Diese Funktion wird nicht aufgerufen werden kann, weil es in iOS 10 über userNotificationCenter() abgeschrieben ist, nicht sicher. Bitte erläutern Sie auch diese ..
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
....Some Code....
}
Ich bin mit iPhone 6s iOS 10 als Debug-Gerät. XCode 8 beta-3
Wenn App nicht oder vom Benutzer getötet läuft und Benachrichtigung empfangen wird dann in einem solchen Szenario, das Sie in didFinishLaunchingWithOptions behandeln müssen und prüfen, ob App über Melde- und Tat geöffnet passend. – user1140780