Share
Embed
Transcript
18 slides
-
ࣗݾհ ϑϦʔϥϯεͷiOSΤϯδχΞΛ͍ͯ͠· ͢ɻ (20168݄͔Βʂ) • Twi%er: @TachibanaKaoru • Blog :
h%p:/ /www.toyship.org/ • ϘϧμϦάϯ͖ -
What's new in No.fica.on of iOS • ௨ʹ"tle/sub"tle͕͚ͭΒΕΔΑ͏ʹͳͬͨ • ௨ʹΠϝʔδը૾͕͚ͭΒΕΔΑ͏ʹͳͬͨ
• ௨ʹCustom UI͕͚ͭΒΕΔΑ͏ʹͳͬͨ • Ϣʔβʔ͕௨ΛڐՄ͔ͨ͠Ͳ͏͔ͷઃఆ͕ͱΕΔΑ͏ʹͳͬ ͨ • ৴ɾະ৴ͷ௨Λ؆୯ʹϋϯυϦϯάͰ͖ΔΑ͏ʹͳͬͨ -
Remote No(fica(on { "aps" : { "alert" : { "title"
: "Introduction to Notifications", "subtitle" : "Session 707", "body" : "Woah! These new notifications look amazing!" }, "badge" : 1 }, } -
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) -
௨ͷཧ ·ͣɺ௨ͷঢ়ଶʹԼهͷ͕̏ͭ͋Γ·͢ɻ • Pending : ·ͩൃՐ͍ͯ͠ͳ͍௨ • Delivered : ൃՐ͕ͨ͠ɺϢʔβʔ͕ॲཧʢλοϓͳͲʣΛͯ͠
͍ͳ͍௨ • (Read) : Ϣʔβʔ͕ॲཧΛͨ͠௨ɹʢ͜ͷঢ়ଶͷ௨औಘͰ ͖·ͤΜɻʣ -
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)") } } -
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 } -
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)") } } -
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])// ͜ΕΛ͍Ε͓ͯ͘ͱɺγεςϜͷ௨ը໘Λͩͯ͘͠ΕΔ }