2017-08-09 3 views
2

私は2つのローカル通知を持っています.1つは、日付に基づいてトリガーし、もう1つは時間に基づいてトリガーします。2つのローカル通知を区別する方法

それらがトリガされるとdidReceiveデリゲートがUNNotificationDefaultActionIdentifier識別子と呼ばれている:

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) { 
    switch response.actionIdentifier { 
    case UNNotificationDismissActionIdentifier: 
     print("Dismiss Action") 
    case UNNotificationDefaultActionIdentifier: 
     // this part is called when notification is triggered 
    ...................................... 
    default: 
     print("Unknown action") 
    } 

    completionHandler() 
} 

は、2つの通知を区別するために、このデリゲートの内部方法はありますか?

どのような通知がトリガーされたかに基づいて異なるアクションが必要です。

答えて

1

応答は、UNNotificationResponseです。

  • actionIdentifier、あなたはそれがUNNotificationRequestのインスタンスのIE 元要求が含まれていUNNotificationあるuserNotificationCenter
  • notificationに追加したカテゴリに相関しているString:これは、2つの不変の性質を持っています。

ので、使用して切り替える:response.notification.request.identifier

1

response.notification.request.identifier 

ショーはこれが

を助け UNNotificationRequest.h

希望であるとしてUNNotificationRequestは、識別子を持って試してみてください

関連する問題