update
This commit is contained in:
18
OrderSchedulingNotificationService/Info.plist
Normal file
18
OrderSchedulingNotificationService/Info.plist
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionPointIdentifier</key>
|
||||
<string>com.apple.usernotifications.service</string>
|
||||
<key>NSExtensionPrincipalClass</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).NotificationService</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
52
OrderSchedulingNotificationService/NotificationService.swift
Normal file
52
OrderSchedulingNotificationService/NotificationService.swift
Normal file
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
let aps = userInfo["aps"] as? [String:Any]
|
||||
if let aps, (aps["alert"] as? String) == "新订单" {
|
||||
let juheVehcileName = userInfo["juheVehcileName"] as? String
|
||||
if juheVehcileName?.isEmpty == false {
|
||||
bestAttemptContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "juheNewOrderAudio.wav"))
|
||||
}else{
|
||||
bestAttemptContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "newOrderAudio.wav"))
|
||||
}
|
||||
}
|
||||
|
||||
JPushNotificationExtensionService.jpushSetAppkey("259b546bb2aaf5f02ffa2547")
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// Use this file to import your target's public headers that you would like to expose to Swift.
|
||||
//
|
||||
|
||||
// 引入 JPush 功能所需头文件
|
||||
# import "JPUSHService.h"
|
||||
# import "JGInforCollectionAuth.h"
|
||||
# import "JPushNotificationExtensionService.h"
|
||||
|
||||
// iOS10 注册 APNs 所需头文件
|
||||
# ifdef NSFoundationVersionNumber_iOS_9_x_Max
|
||||
# import <UserNotifications/UserNotifications.h>
|
||||
# endif
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict/>
|
||||
</plist>
|
||||
Reference in New Issue
Block a user