Commit 448f2347 authored by shigemi miura's avatar shigemi miura

push通知対応

parent eb4a0456
...@@ -76,7 +76,6 @@ ...@@ -76,7 +76,6 @@
02CE4DDA2ADFBA72002E79BC /* MapRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02CE4DD92ADFBA72002E79BC /* MapRepresentable.swift */; }; 02CE4DDA2ADFBA72002E79BC /* MapRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02CE4DD92ADFBA72002E79BC /* MapRepresentable.swift */; };
02F4DB672B2C173F00E86C41 /* SessionGetManualUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F4DB662B2C173F00E86C41 /* SessionGetManualUrl.swift */; }; 02F4DB672B2C173F00E86C41 /* SessionGetManualUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F4DB662B2C173F00E86C41 /* SessionGetManualUrl.swift */; };
A0F472F6BC78C5F1C5471836 /* Pods_SailAssistTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D252BA721FD314FAE4C2B4C /* Pods_SailAssistTests.framework */; }; A0F472F6BC78C5F1C5471836 /* Pods_SailAssistTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D252BA721FD314FAE4C2B4C /* Pods_SailAssistTests.framework */; };
D51AA4042B099DCD00EBBDD4 /* SignalRService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D51AA4032B099DCD00EBBDD4 /* SignalRService.swift */; };
D51AA4072B099FCC00EBBDD4 /* AlertDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = D51AA4062B099FCC00EBBDD4 /* AlertDB.swift */; }; D51AA4072B099FCC00EBBDD4 /* AlertDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = D51AA4062B099FCC00EBBDD4 /* AlertDB.swift */; };
D5258C992B0334BF00365276 /* SessionShipStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5258C982B0334BF00365276 /* SessionShipStatus.swift */; }; D5258C992B0334BF00365276 /* SessionShipStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5258C982B0334BF00365276 /* SessionShipStatus.swift */; };
D5258C9B2B03401E00365276 /* MonitoringRoute.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5258C9A2B03401E00365276 /* MonitoringRoute.swift */; }; D5258C9B2B03401E00365276 /* MonitoringRoute.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5258C9A2B03401E00365276 /* MonitoringRoute.swift */; };
...@@ -238,7 +237,6 @@ ...@@ -238,7 +237,6 @@
B422ACD189FD390D51F10007 /* Pods-SailAssistTests.qc.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SailAssistTests.qc.xcconfig"; path = "Target Support Files/Pods-SailAssistTests/Pods-SailAssistTests.qc.xcconfig"; sourceTree = "<group>"; }; B422ACD189FD390D51F10007 /* Pods-SailAssistTests.qc.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SailAssistTests.qc.xcconfig"; path = "Target Support Files/Pods-SailAssistTests/Pods-SailAssistTests.qc.xcconfig"; sourceTree = "<group>"; };
C0CBB553F04E0BB4ACC72BD1 /* Pods-Sailassist.qc.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Sailassist.qc.xcconfig"; path = "Target Support Files/Pods-Sailassist/Pods-Sailassist.qc.xcconfig"; sourceTree = "<group>"; }; C0CBB553F04E0BB4ACC72BD1 /* Pods-Sailassist.qc.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Sailassist.qc.xcconfig"; path = "Target Support Files/Pods-Sailassist/Pods-Sailassist.qc.xcconfig"; sourceTree = "<group>"; };
CA31D32D54D7C200EF057679 /* Pods-SailAssistTests.canary.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SailAssistTests.canary.xcconfig"; path = "Target Support Files/Pods-SailAssistTests/Pods-SailAssistTests.canary.xcconfig"; sourceTree = "<group>"; }; CA31D32D54D7C200EF057679 /* Pods-SailAssistTests.canary.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SailAssistTests.canary.xcconfig"; path = "Target Support Files/Pods-SailAssistTests/Pods-SailAssistTests.canary.xcconfig"; sourceTree = "<group>"; };
D51AA4032B099DCD00EBBDD4 /* SignalRService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SignalRService.swift; path = Sailassist/SignalR/SignalRService.swift; sourceTree = SOURCE_ROOT; };
D51AA4062B099FCC00EBBDD4 /* AlertDB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AlertDB.swift; path = Sailassist/DataSource/AlertDB.swift; sourceTree = SOURCE_ROOT; }; D51AA4062B099FCC00EBBDD4 /* AlertDB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AlertDB.swift; path = Sailassist/DataSource/AlertDB.swift; sourceTree = SOURCE_ROOT; };
D5258C982B0334BF00365276 /* SessionShipStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SessionShipStatus.swift; path = Sailassist/ServerSession/SessionShipStatus.swift; sourceTree = SOURCE_ROOT; }; D5258C982B0334BF00365276 /* SessionShipStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SessionShipStatus.swift; path = Sailassist/ServerSession/SessionShipStatus.swift; sourceTree = SOURCE_ROOT; };
D5258C9A2B03401E00365276 /* MonitoringRoute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MonitoringRoute.swift; path = Sailassist/Map/MonitoringRoute.swift; sourceTree = SOURCE_ROOT; }; D5258C9A2B03401E00365276 /* MonitoringRoute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MonitoringRoute.swift; path = Sailassist/Map/MonitoringRoute.swift; sourceTree = SOURCE_ROOT; };
...@@ -351,7 +349,6 @@ ...@@ -351,7 +349,6 @@
D5384AFF2B3121FA006228C6 /* html */, D5384AFF2B3121FA006228C6 /* html */,
D545FC722B09C6DA00F206D0 /* VoiceManager */, D545FC722B09C6DA00F206D0 /* VoiceManager */,
D51AA4052B099F6D00EBBDD4 /* DataSource */, D51AA4052B099F6D00EBBDD4 /* DataSource */,
D51AA4022B099DA600EBBDD4 /* SignalR */,
D5EA86482AF2139D0032E810 /* Location */, D5EA86482AF2139D0032E810 /* Location */,
D52D213B2AEBB78E00324D58 /* ECA */, D52D213B2AEBB78E00324D58 /* ECA */,
D52D21382AEBABE700324D58 /* Http */, D52D21382AEBABE700324D58 /* Http */,
...@@ -677,14 +674,6 @@ ...@@ -677,14 +674,6 @@
path = Pods; path = Pods;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
D51AA4022B099DA600EBBDD4 /* SignalR */ = {
isa = PBXGroup;
children = (
D51AA4032B099DCD00EBBDD4 /* SignalRService.swift */,
);
path = SignalR;
sourceTree = "<group>";
};
D51AA4052B099F6D00EBBDD4 /* DataSource */ = { D51AA4052B099F6D00EBBDD4 /* DataSource */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -1046,7 +1035,6 @@ ...@@ -1046,7 +1035,6 @@
D55135202B15B030007B66B1 /* SetEcaArea.swift in Sources */, D55135202B15B030007B66B1 /* SetEcaArea.swift in Sources */,
D592D5272B0F182C00B91A1C /* ReqAckMessage.swift in Sources */, D592D5272B0F182C00B91A1C /* ReqAckMessage.swift in Sources */,
D592D5292B0F198100B91A1C /* ReqChatModeMessage.swift in Sources */, D592D5292B0F198100B91A1C /* ReqChatModeMessage.swift in Sources */,
D51AA4042B099DCD00EBBDD4 /* SignalRService.swift in Sources */,
025C27FA2AFE119D00BADC49 /* MenuTitleView.swift in Sources */, 025C27FA2AFE119D00BADC49 /* MenuTitleView.swift in Sources */,
02CE4D892ADF62E1002E79BC /* EcaSettingView.swift in Sources */, 02CE4D892ADF62E1002E79BC /* EcaSettingView.swift in Sources */,
025F99722B2AE3AF00C9A18A /* TaskViewModel.swift in Sources */, 025F99722B2AE3AF00C9A18A /* TaskViewModel.swift in Sources */,
......
...@@ -13,7 +13,7 @@ struct ChatView: View { ...@@ -13,7 +13,7 @@ struct ChatView: View {
@State var isShowMember: Bool = false @State var isShowMember: Bool = false
var body: some View { var body: some View {
ZStack { ZStack {
if message.mode == 1{ if message.mode == true{
LinearGradient(gradient: Gradient(colors: [.chatEmargencyColor1, .chatEmargencyColor2]), startPoint: .top, endPoint: .bottom) LinearGradient(gradient: Gradient(colors: [.chatEmargencyColor1, .chatEmargencyColor2]), startPoint: .top, endPoint: .bottom)
.ignoresSafeArea() .ignoresSafeArea()
} }
......
...@@ -18,7 +18,11 @@ class GetMessage { ...@@ -18,7 +18,11 @@ class GetMessage {
let serverSession = ServerSession() let serverSession = ServerSession()
let resjson = serverSession.fromJSON(resultData: resultData, resltType: ResGetMessages.self) let resjson = serverSession.fromJSON(resultData: resultData, resltType: ResGetMessages.self)
if let res = resjson { if let res = resjson {
SharingData.message.mode = res.mode if res.mode == 1 {
SharingData.message.mode = true
} else {
SharingData.message.mode = false
}
SharingData.message.messages = [] SharingData.message.messages = []
if let msg = res.messages { if let msg = res.messages {
SharingData.message.messages = msg SharingData.message.messages = msg
......
...@@ -9,7 +9,6 @@ import SwiftUI ...@@ -9,7 +9,6 @@ import SwiftUI
struct ChatInputView: View { struct ChatInputView: View {
@EnvironmentObject private var sceneDelegate: SceneDelegate @EnvironmentObject private var sceneDelegate: SceneDelegate
@EnvironmentObject var signalRService: SignalRService
@State var inputText = "" @State var inputText = ""
@FocusState var isKeyboard : Bool @FocusState var isKeyboard : Bool
...@@ -33,6 +32,7 @@ struct ChatInputView: View { ...@@ -33,6 +32,7 @@ struct ChatInputView: View {
Button{ Button{
isKeyboard = false isKeyboard = false
let signalRService = SignalR()
signalRService.chatMessage(message: inputText) signalRService.chatMessage(message: inputText)
inputText = "" inputText = ""
} label: { } label: {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
import SwiftUI import SwiftUI
import UserNotifications import UserNotifications
import WindowsAzureMessaging import WindowsAzureMessaging
import SwiftSignalRClient
@main @main
struct SailassistApp: App { struct SailassistApp: App {
...@@ -16,7 +17,6 @@ struct SailassistApp: App { ...@@ -16,7 +17,6 @@ struct SailassistApp: App {
@State private var isPrivAgree = Preferences.privacyPolicyAgreeDate != nil @State private var isPrivAgree = Preferences.privacyPolicyAgreeDate != nil
let locationViewModel = LocationViewModel() let locationViewModel = LocationViewModel()
let signalRService = SignalRService()
var body: some Scene { var body: some Scene {
WindowGroup { WindowGroup {
...@@ -53,7 +53,6 @@ struct SailassistApp: App { ...@@ -53,7 +53,6 @@ struct SailassistApp: App {
} else { } else {
ContentView() ContentView()
.environmentObject(locationViewModel) .environmentObject(locationViewModel)
.environmentObject(signalRService)
} }
} }
} }
...@@ -74,7 +73,9 @@ class NotificationTags: NSObject { ...@@ -74,7 +73,9 @@ class NotificationTags: NSObject {
} }
} }
private var connection: HubConnection?
class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, MSInstallationLifecycleDelegate { class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, MSInstallationLifecycleDelegate {
private var hubConnectionDelegate: HubConnectionDelegate?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
print(debug: "called") print(debug: "called")
...@@ -99,6 +100,28 @@ class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, M ...@@ -99,6 +100,28 @@ class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, M
Preferences.DeviceId = UUID().uuidString Preferences.DeviceId = UUID().uuidString
} }
hubConnectionDelegate = ChatHubConnectionDelegate(app: self)
connection = HubConnectionBuilder(url: URL(string : HttpRequestType.SignalR.rawValue)!)
.withHubConnectionDelegate(delegate: hubConnectionDelegate!)
.withAutoReconnect()
.withLogging(minLogLevel: .error)
.withHubConnectionOptions(configureHubConnectionOptions: {options in options.keepAliveInterval = 20 })
.build()
connection!.on(method: "chatMessage", callback: { (message: ResChatMessage) in
self.handleChatMessage(message: message)
})
connection!.on(method: "ackMessage", callback: { (message: ResAckMessage) in
self.handleAckMessage(message: message)
})
connection!.on(method: "chatMode", callback: { (message: ResChatMode) in
self.handleChatMessage(message: message)
})
connection!.start()
return true return true
} }
...@@ -142,6 +165,102 @@ class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, M ...@@ -142,6 +165,102 @@ class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, M
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("APNs 登録に失敗しました : \(error.localizedDescription)") print("APNs 登録に失敗しました : \(error.localizedDescription)")
} }
private func handleChatMessage(message: ResChatMessage) {
print(debug: "called")
}
private func handleAckMessage(message: ResAckMessage) {
print(debug: "called")
}
private func handleChatMessage(message: ResChatMode) {
print(debug: "called")
}
// func applicationWillTerminate(_ aNotification: Notification) {
// connection.stop()
// }
}
class SignalR: NSObject {
func chatMessage(message: String) {
var request = ReqMessage(shipId: Preferences.shipId, messageId: UUID().uuidString)
request.type = 0 //0:テキスト, 1:スタンプ
request.time = DateTextLib.Date2ISO8601Text(Date())
request.location = 2 //1:Shore , 2:Ship
request.from = Preferences.UserName //投稿者名
request.fromeId = SharingData.my.id //ユーザーID
request.message = message //テキスト
// request.stampId = //スタンプ番号 0:Fire~
if message != "" {
connection!.invoke(method: "chatMessage", request) { error in
if let e = error {
print(debug: "Error:\(e)")
}
}
}
}
func ackMessage(messageId: String) {
var request = ReqAckMessage(shipId: Preferences.shipId, messageId: messageId)
request.time = DateTextLib.Date2ISO8601Text(Date())
request.location = 2 //1:Shore , 2:Ship
request.fromeId = SharingData.my.id //ユーザーID
if messageId != "" {
connection!.invoke(method: "ackMessage", request) { error in
if let e = error {
print(debug: "Error:\(e)")
}
}
}
}
func chatMode(mode: Bool) {
var request = ReqChatModeMessage(shipId: Preferences.shipId)
request.time = DateTextLib.Date2ISO8601Text(Date())
request.location = 2 //1:Shore , 2:Ship
request.fromeId = SharingData.my.id //ユーザーID
if mode == true{
request.mode = 1
} else {
request.mode = 0
}
connection!.invoke(method: "chatMode", request) { error in
if let e = error {
print(debug: "Error:\(e)")
}
}
}
}
class ChatHubConnectionDelegate: HubConnectionDelegate {
weak var app: AppDelegate?
init(app: AppDelegate) {
self.app = app
}
func connectionDidOpen(hubConnection: HubConnection) {
// app?.connectionDidStart()
}
func connectionDidFailToOpen(error: Error) {
// app?.connectionDidFailToOpen(error: error)
}
func connectionDidClose(error: Error?) {
// app?.connectionDidClose(error: error)
}
func connectionWillReconnect(error: Error) {
// app?.connectionWillReconnect(error: error)
}
func connectionDidReconnect() {
// app?.connectionDidReconnect()
}
} }
extension AppDelegate: UNUserNotificationCenterDelegate { extension AppDelegate: UNUserNotificationCenterDelegate {
...@@ -150,12 +269,33 @@ extension AppDelegate: UNUserNotificationCenterDelegate { ...@@ -150,12 +269,33 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
willPresent notification: UNNotification, willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo let userInfo = notification.request.content.userInfo
print(debug: userInfo)
if !userInfo.isEmpty { if !userInfo.isEmpty {
guard userInfo["sendType"] is String else { guard let arrAPS = userInfo["aps"] as? [String: Any] else {
completionHandler([.badge, .sound, .banner, .list]) completionHandler([[.banner, .badge, .sound]])
return return
} }
let arrCategory = arrAPS["category"] as? String ?? ""
switch arrCategory {
case "chat":
guard let arrAlert = arrAPS["alert"] as? [String: Any] else {
completionHandler([[.banner, .badge, .sound]])
return
}
// let subtitle = arrAlert["subtitle"] as? String ?? "" //送信先名称
// let strTitle = arrAlert["title"] as? String ?? "" //送信内容
// let strBody = arrAlert["body"] as? String ?? "" //船名
let message = GetMessage()
message.start()
case "sailassist":
print(debug: "sailassist")
case "bam":
print(debug: "bam")
case "route":
print(debug: "route")
default:
print(debug: "default")
}
} }
completionHandler([[.banner, .badge, .sound]]) completionHandler([[.banner, .badge, .sound]])
} }
...@@ -166,12 +306,32 @@ extension AppDelegate: UNUserNotificationCenterDelegate { ...@@ -166,12 +306,32 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
withCompletionHandler completionHandler: @escaping () -> Void) { withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo let userInfo = response.notification.request.content.userInfo
print(debug: userInfo) print(debug: userInfo)
if !userInfo.isEmpty {
guard let arrAPS = userInfo["aps"] as? [String: Any] else {
completionHandler()
return
}
if let custom = userInfo["key"] as? String { let arrCategory = arrAPS["category"] as? String ?? ""
print(debug: "called \(custom)") switch arrCategory {
case "chat":
if custom == "map" { guard let arrAlert = arrAPS["alert"] as? [String: Any] else {
completionHandler()
return
}
// let subtitle = arrAlert["subtitle"] as? String ?? "" //送信先名称
// let strTitle = arrAlert["title"] as? String ?? "" //送信内容
// let strBody = arrAlert["body"] as? String ?? "" //船名
let message = GetMessage()
message.start()
case "sailassist":
print(debug: "sailassist")
case "bam":
print(debug: "bam")
case "route":
print(debug: "route")
default:
print(debug: "default")
} }
} }
completionHandler() completionHandler()
......
...@@ -73,8 +73,12 @@ class SharingData{ ...@@ -73,8 +73,12 @@ class SharingData{
static var message = Message() static var message = Message()
class Message: ObservableObject { class Message: ObservableObject {
@Published var mode: Int = 0 // 0:通常 , 1:Warning中 @Published var mode: Bool = false // false:通常 , true:Warning中
@Published var messages: [ChatMessage] = [] @Published var messages: [ChatMessage] = []
func changeMode(){
self.mode.toggle()
}
} }
/** /**
......
//
// SignalRService.swift
// Sailassist
//
// Created by 三浦薫巳 on 2023/11/17.
//
import Foundation
import SwiftSignalRClient
class SignalRService: ObservableObject{
private var connection: HubConnection
private var hubConnectionDelegate: HubConnectionDelegate?
public init() {
// hubConnectionDelegate = ChatHubConnectionDelegate(controller: self)
hubConnectionDelegate = ChatHubConnectionDelegate()
connection = HubConnectionBuilder(url: URL(string : HttpRequestType.SignalR.rawValue)!)
.withHubConnectionDelegate(delegate: hubConnectionDelegate!)
.withAutoReconnect()
.withLogging(minLogLevel: .error)
.withHubConnectionOptions(configureHubConnectionOptions: {options in options.keepAliveInterval = 20 })
.build()
connection.on(method: "chatMessage", callback: { (message: ResChatMessage) in
self.handleChatMessage(message: message)
})
connection.on(method: "ackMessage", callback: { (message: ResAckMessage) in
self.handleAckMessage(message: message)
})
connection.on(method: "chatMode", callback: { (message: ResChatMode) in
self.handleChatMessage(message: message)
})
connection.start()
}
private func handleChatMessage(message: ResChatMessage) {
print(debug: "called")
}
private func handleAckMessage(message: ResAckMessage) {
print(debug: "called")
}
private func handleChatMessage(message: ResChatMode) {
print(debug: "called")
}
func applicationWillTerminate(_ aNotification: Notification) {
connection.stop()
}
//呼び出す
func chatMessage(message: String) {
var request = ReqMessage(shipId: Preferences.shipId, messageId: UUID().uuidString)
request.type = 0 //0:テキスト, 1:スタンプ
request.time = DateTextLib.Date2ISO8601Text(Date())
request.location = 2 //1:Shore , 2:Ship
request.from = Preferences.UserName //投稿者名
request.fromeId = SharingData.my.id //ユーザーID
request.message = message //テキスト
// request.stampId = //スタンプ番号 0:Fire~
if message != "" {
connection.invoke(method: "chatMessage", request) { error in
if let e = error {
print(debug: "Error:\(e)")
}
}
}
}
func ackMessage(messageId: String) {
var request = ReqAckMessage(shipId: Preferences.shipId, messageId: messageId)
request.time = DateTextLib.Date2ISO8601Text(Date())
request.location = 2 //1:Shore , 2:Ship
request.fromeId = SharingData.my.id //ユーザーID
if messageId != "" {
connection.invoke(method: "ackMessage", request) { error in
if let e = error {
print(debug: "Error:\(e)")
}
}
}
}
func chatMode() {
var request = ReqChatModeMessage(shipId: Preferences.shipId)
request.time = DateTextLib.Date2ISO8601Text(Date())
request.location = 2 //1:Shore , 2:Ship
request.fromeId = SharingData.my.id //ユーザーID
request.mode = 0 //0:通常 / 1:Warning中
connection.invoke(method: "chatMode", request) { error in
if let e = error {
print(debug: "Error:\(e)")
}
}
}
// func chatMode2(_ message: String) {
// connection.send(method: "Broadcast", "Playground user", "Testing send") { error in
// if let error = error {
// print("Send failed: \(error)")
// }
// }
// }
}
class ChatHubConnectionDelegate: HubConnectionDelegate {
// weak var app: SignalRService?
//
// init(app: SignalRService) {
// self.app = app
// }
//接続が正常に開始されたときに発生
func connectionDidOpen(hubConnection: HubConnection) {
print("connectionDidOpen")
// After connection established call registerUserInServer method
DispatchQueue.main.async {
// self.registerUserInServer()
}
}
//接続を正常に開始できなかったときに発生
func connectionDidFailToOpen(error: Error) {
print("connectionDidFailToOpen")
}
func connectionDidClose(error: Error?) {
print("connectionDidClose")
}
func connectionWillReconnect(error: Error) {
print("connectionWillReconnect")
}
func connectionDidReconnect() {
print("connectionDidReconnect")
}
}
...@@ -99,11 +99,9 @@ struct CustomTabBar: View { ...@@ -99,11 +99,9 @@ struct CustomTabBar: View {
.background(ColorSet.BottomNav.color) .background(ColorSet.BottomNav.color)
.alert("", isPresented: $selectedTabModel.isShowChangeEmrMode) { .alert("", isPresented: $selectedTabModel.isShowChangeEmrMode) {
Button("Yes"){ Button("Yes"){
if SharingData.message.mode == 0{ SharingData.message.changeMode()
SharingData.message.mode = 1 let signalRService = SignalR()
}else{ signalRService.chatMode(mode: SharingData.message.mode)
SharingData.message.mode = 0
}
} }
Button("No"){ Button("No"){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment