クリック時にUNUserNotificationCenter関数が呼び出されないアクションボタンアプリケーションがアクティブでない場合に3Dタッチ後にチャット通知を行います。アプリケーションが終了したときに、Xcodeで「名前でプロセスにアタッチ」してアプリケーションをデバッグしました。ここでは、コードは次のとおりです。この機能が最初に呼び出される(MixPanelから送られた)通知ポップアップUNUserNotificationCenter didRecieveレスポンスは、アプリケーションが終了した場合に呼び出されません。
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
}
、
コール1:
func handlePushNotificationWithUserInfo(launchOptions: [NSObject: AnyObject]?) {
//Handle PushNotification when app is opened
}
それは
、ここに行きますコール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()
}
コール3:機能以下
// remote notification
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
....Some Code....
}
しかしは呼び出されません。 アプリがバックグラウンドで実行されている場合以下の機能が呼び出され、はすべて正常に動作します。それ以外の場合は、アプリケーションはフォアグラウンドになり、チャットはになりません。
// 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])
}
}
この機能は、それがuserNotificationCenter上のiOS 10に減価償却ているため、)(わからないかもしれ呼び出されることはありません。私はデバッグ装置としてiPhoneのiOS 6秒10を使用しています
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
....Some Code....
}
...また、これを説明してください。次のようスウィフト3 &のXcode 8にローカル通知を受け XCodeの8ベータ3
アプリが実行しているか、ユーザーとの通知によって殺されていないようなシナリオで、次に受信します適切に。 – user1140780