修复发送到其他设备快捷指令异常的问题

This commit is contained in:
Fin 2025-02-24 09:51:23 +08:00
parent 786e5f2232
commit 2bc0eb33b8
2 changed files with 18 additions and 15 deletions

View File

@ -41,15 +41,16 @@ struct PushToCurrentIntent: AppIntent {
var group: String?
func perform() async throws -> some IntentResult & ReturnsValue<Bool> {
let url = ServerManager.shared.currentServer.address + "/\(ServerManager.shared.currentServer.key)"
guard let address = URL(string: address) else {
throw "Invalid URL"
}
var params: [String: Any] = [:]
if let title {
if let title, !title.isEmpty {
params["title"] = title.urlDecoded()
}
if let body {
// url body
if let body, !body.isEmpty {
params["body"] = body.urlDecoded()
}
if title == nil, body == nil {
@ -64,17 +65,17 @@ struct PushToCurrentIntent: AppIntent {
if isCall {
params["call"] = 1
}
if let sound {
if let sound, !sound.isEmpty {
params["sound"] = sound
}
if let icon {
params["icon"] = icon.absoluteString
}
if let group {
if let group, !group.isEmpty {
params["group"] = group
}
let response = await AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default)
let response = await AF.request(address, method: .post, parameters: params, encoding: JSONEncoding.default)
.serializingDecodable(PushResponse.self)
.response

View File

@ -40,15 +40,17 @@ struct PushToOtherIntent: AppIntent {
var group: String?
func perform() async throws -> some IntentResult & ReturnsValue<Bool> {
let url = ServerManager.shared.currentServer.address + "/\(ServerManager.shared.currentServer.key)"
guard let address = URL(string: address) else {
throw "Invalid URL"
}
var params: [String: Any] = [:]
if let title {
params["title"] = title
if let title, !title.isEmpty {
params["title"] = title.urlDecoded()
}
if let body {
params["body"] = body
if let body, !body.isEmpty {
params["body"] = body.urlDecoded()
}
if title == nil, body == nil {
params["body"] = "Empty Notification"
@ -62,17 +64,17 @@ struct PushToOtherIntent: AppIntent {
if isCall {
params["call"] = 1
}
if let sound {
if let sound, !sound.isEmpty {
params["sound"] = sound
}
if let icon {
params["icon"] = icon.absoluteString
}
if let group {
if let group, !group.isEmpty {
params["group"] = group
}
let response = await AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default)
let response = await AF.request(address, method: .post, parameters: params, encoding: JSONEncoding.default)
.serializingDecodable(PushResponse.self)
.response