Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Notifications in iOS10

Notifications in iOS10

Tachibana Kaoru

July 21, 2016
Tweet

More Decks by Tachibana Kaoru

Other Decks in Technology

Transcript

  1. What's new in No.fica.on of iOS • ௨஌ʹ"tle/sub"tle͕͚ͭΒΕΔΑ͏ʹͳͬͨ • ௨஌ʹΠϝʔδ΍ը૾͕͚ͭΒΕΔΑ͏ʹͳͬͨ

    • ௨஌ʹCustom UI͕͚ͭΒΕΔΑ͏ʹͳͬͨ • Ϣʔβʔ͕௨஌ΛڐՄ͔ͨ͠Ͳ͏͔ͷઃఆ͕ͱΕΔΑ͏ʹͳͬ ͨ • ഑৴ɾະ഑৴ͷ௨஌Λ؆୯ʹϋϯυϦϯάͰ͖ΔΑ͏ʹͳͬͨ
  2. Remote No(fica(on { "aps" : { "alert" : { "title"

    : "Introduction to Notifications", "subtitle" : "Session 707", "body" : "Woah! These new notifications look amazing!" }, "badge" : 1 }, }
  3. Local No(fica(on let center = UNUserNotificationCenter.current() let content = UNMutableNotificationContent()

    content.title = "Hello" content.body = "This is a big news!" content.sound = UNNotificationSound.default() let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 10, repeats: false) let request = UNNotificationRequest.init( identifier: "NewsUpdate", // ͜ͷIDΛΩʔʹͯ͠࡟আ΍ฤूΛ͠·͢ content: content, trigger: trigger) center.add(request)
  4. get pending no*fica*ons UNUserNotificationCenter.current().getPendingNotificationRequests { requests in print("== Pending Notification

    : \(requests.count) == ") for request in requests { request.identifier request.content.title request.content.subtitle request.content.body request.trigger print(" -- title : \(request.content.title) body:\(request.content.body)") } }
  5. update pending no,fica,ons // ৽͍͠contentΛͭ͘Δ let content = UNMutableNotificationContent() content.title

    = "Hello" content.body = "This is a more big news!" content.sound = UNNotificationSound.default() let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false) // ৽͍͠requestΛͭ͘Δ let newRequest = UNNotificationRequest.init(identifier: "NewsUpdate", content: content, trigger: trigger) // ৽͍͠requestΛͭ͘Δʢݹ͍΋ͷΛdelete͢Δඞཁ͸ͳ͍ʣ UNUserNotificationCenter.current().add(newRequest) { error in // error }
  6. get delivered no,fica,ons UNUserNotificationCenter.current().getDeliveredNotifications { notifications in // [UNNotification]) print("==

    Delivred Notification : \(notifications.count) == ") for notification in notifications { notification.date notification.request print(" -- title : \(notification.request.content.title) body:\(notification.request.content.body) date: \(notification.date)") } }
  7. No#fica#on in ac#on • ΞϓϦ͕ Foregroundʹ͋Δঢ়ଶͰ௨஌͕഑৴͞Εͨ৔߹ʹɺγ εςϜͷ௨஌ը໘ΛͩͤΔΑ͏ʹͳΓ·ͨ͠ɻ func userNotificationCenter(_ center:

    UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) { print("! Notification came!\(notification.request.content.title)") completionHandler([.alert, .sound])// ͜ΕΛ͍Ε͓ͯ͘ͱɺγεςϜͷ௨஌ը໘Λͩͯ͘͠ΕΔ }