iOS
#21
2016/12/26
@m_orishi
• (@m_orishi)
• iOS
•
•
2016
UP ❤
2017 3 8 ( )
iOS10 PUSH
Push
• NWPusher (noodlewerk/NWPusher)
• Mac Keychain Push
Push
{
"aps": {
"alert": {
"title": " ",
"subtitle": " ",
"body": " "
},
"badge": 1,
"mutable-content": 1
},
"image_url": " URL"
}
http://qiita.com/himara2/items/dcfcc30b550c3304d86a
“iOS 10 Notification
”
“[iOS10]
(PHP ”
http://qiita.com/eKushida/items/634ad3726868c8f5e61d
Push 🙇
Push
• Capabilities Push Notifications ON
• APNs
Push
Push
• Xcode File > New > Target
•
UNNotificationServiceExtension
NotificationService
Notification Service Extension
(NotificationService.swift)
import UserNotifications
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest,
withContentHandler contentHandler: @escaping (UNNotificationContent) ->
Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
bestAttemptContent.title = "(bestAttemptContent.title) [modified]"
contentHandler(bestAttemptContent)
}
}
override func serviceExtensionTimeWillExpire() {
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
}
Push
• request.content.userInfo[“image_url"]
URL
• URL
• UNNotificationAttachment
attachments contentHandler Call
Push Data Attach
Extension Code Sample
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let imageUrl = request.content.userInfo["image_url"] as? String {
let session = URLSession(configuration: URLSessionConfiguration.default)
let task = session.dataTask(with: URL(string: imageUrl)!,
completionHandler: {[weak self](data, response, error) in
do {
if let writePath = NSURL(fileURLWithPath:NSTemporaryDirectory())
.appendingPathComponent("tmp.jpg") {
try data?.write(to: writePath)
if let bestAttemptContent = self?.bestAttemptContent {
bestAttemptContent.title = "(bestAttemptContent.title) [modified]"
// Attach Image.
let attachment = try UNNotificationAttachment(identifier: “id",
url: writePath,
options: nil)
bestAttemptContent.attachments = [attachment]
contentHandler(bestAttemptContent)
}
} else {
print("URL ")
if let bestAttemptContent = self?.bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
} catch let error as NSError {
if let bestAttemptContent = self?.bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
})
task.resume()
} else {
// Non imageURL.
if let bestAttemptContent = self.bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
AspectFill
• ATS Notification Service Extension
Info.plist
• NWPusher proxy
•
(30s)
• NotificationServiceExtension
• Push
💕
• Notification
(firebase/quickstart-ios/issues/70)
→
• Documentation-Guides $
English
Firebase Notification 😢

iOS NotificationService