Files
OrderScheduling/OrderSchedulingNotificationService/NotificationService.swift
DDIsFriend cae8beeb03 update
2023-08-30 14:26:08 +08:00

60 lines
2.4 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// NotificationService.swift
// OrderSchedulingNotificationService
//
// Created by on 2023/8/28.
//
import UserNotifications
import AVFoundation
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 {
// Modify the notification content here...
// bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
let userInfo = bestAttemptContent.userInfo
// group
let aps = userInfo[aps_key] as? [String:Any]
if let aps, (aps[alert_key] as? String) == "新订单" {
var sound : UNNotificationSound?
let juheVehcileName = userInfo[juheVehcileName_key] as? String
if juheVehcileName?.isEmpty == false {
sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: juheNewOrderAudio_key))
}else{
sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: newOrderAudio_key))
}
bestAttemptContent.sound = sound
GROUP.setBestAttemptContentUserInfo(bestAttemptContentUserInfo: userInfo)
}
JPushNotificationExtensionService.jpushSetAppkey(JPushKey)
JPushNotificationExtensionService.jpushReceive(request) {
contentHandler(request.content)
}
contentHandler(bestAttemptContent)
}
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
}