✨ New NSE and hold notification to reply
This commit is contained in:
@ -3,11 +3,14 @@ import UIKit
|
||||
|
||||
@main
|
||||
@objc class AppDelegate: FlutterAppDelegate {
|
||||
let notifyDelegate = NotifyDelegate()
|
||||
|
||||
override func application(
|
||||
_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
||||
) -> Bool {
|
||||
GeneratedPluginRegistrant.register(with: self)
|
||||
UNUserNotificationCenter.current().delegate = notifyDelegate
|
||||
GeneratedPluginRegistrant.register(with: self)
|
||||
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,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>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>CADisableMinimumFrameDurationOnPhone</key>
|
||||
<true/>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
|
54
ios/Runner/NotifyDelegate.swift
Normal file
54
ios/Runner/NotifyDelegate.swift
Normal file
@ -0,0 +1,54 @@
|
||||
//
|
||||
// NotifyDelegate.swift
|
||||
// Runner
|
||||
//
|
||||
// Created by LittleSheep on 2025/6/1.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
|
||||
class NotifyDelegate: UIResponder, UNUserNotificationCenterDelegate {
|
||||
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
||||
if let textResponse = response as? UNTextInputNotificationResponse {
|
||||
let content = response.notification.request.content
|
||||
guard let metadata = content.userInfo["meta"] as? [AnyHashable: Any] else {
|
||||
return
|
||||
}
|
||||
|
||||
var token: String = ""
|
||||
if let tokenJson = UserDefaults.standard.string(forKey: "dyn_user_tk"),
|
||||
let tokenData = tokenJson.data(using: String.Encoding.utf8),
|
||||
let tokenDict = try? JSONSerialization.jsonObject(with: tokenData) as? [String: Any],
|
||||
let tokenValue = tokenDict["token"] as? String {
|
||||
token = tokenValue
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
let serverUrl = "https://nt.solian.app"
|
||||
let url = "\(serverUrl)/chat/\(metadata["room_id"])/messages"
|
||||
|
||||
let parameters: [String: Any] = [
|
||||
"content": textResponse.userText,
|
||||
"replied_message_id": metadata["message_id"]
|
||||
]
|
||||
|
||||
AF.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: HTTPHeaders(
|
||||
[HTTPHeader(name: "Authorization", value: "AtField \(token)")]
|
||||
))
|
||||
.validate()
|
||||
.responseString { response in
|
||||
switch response.result {
|
||||
case .success(_):
|
||||
break
|
||||
case .failure(let error):
|
||||
print("Failed to send chat reply message: \(error)")
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
completionHandler()
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
import Foundation
|
||||
|
||||
func getAttachmentUrl(for identifier: String) -> String {
|
||||
let serverBaseUrl = "https://api.sn.solsynth.dev"
|
||||
let serverBaseUrl = "https://nt.solian.app"
|
||||
|
||||
return identifier.starts(with: "http") ? identifier : "\(serverBaseUrl)/cgi/uc/attachments/\(identifier)"
|
||||
return identifier.starts(with: "http") ? identifier : "\(serverBaseUrl)/files/\(identifier)"
|
||||
}
|
||||
|
Reference in New Issue
Block a user