forked from AcaMate/AcaMate_iOS
111 lines
4.1 KiB
Swift
111 lines
4.1 KiB
Swift
//
|
|
// Alert.swift
|
|
// AcaMate
|
|
//
|
|
// Created by Sean Kim on 12/2/24.
|
|
//
|
|
|
|
import SwiftUI
|
|
import Combine
|
|
|
|
struct AlertData {
|
|
var title: String
|
|
var body: String
|
|
var button: [ButtonType]
|
|
|
|
init(title: String = "알림", body: String, button: [ButtonType] = [.init(name: "확인", role: .none, function: nil)]) {
|
|
self.title = title
|
|
self.body = body
|
|
self.button = button
|
|
}
|
|
}
|
|
|
|
struct ButtonType {
|
|
var name: String
|
|
var role: ButtonRole?
|
|
var function: (()->())?
|
|
}
|
|
|
|
|
|
|
|
struct SetAlertData {
|
|
func setTest() -> AlertData {
|
|
return AlertData(title: "TEST", body: "TEST용 알럿 입니다.",
|
|
button: [
|
|
ButtonType(name: "테스트", role: .cancel,
|
|
function: {
|
|
printLog("테스트 중입니다.")
|
|
})
|
|
])
|
|
}
|
|
|
|
|
|
/// 강제 업데이트 안내
|
|
func setForceUpdate(action: CurrentValueSubject<String?, Never>) -> AlertData {
|
|
return AlertData(title: "업데이트 안내",
|
|
body: """
|
|
앱 최신 버전이 나왔습니다.
|
|
앱을 종료 후 업데이트를 해주세요.
|
|
""",
|
|
button: [
|
|
ButtonType(name: "업데이트 하기", role: .none,
|
|
function: {
|
|
action.send("updateNow")
|
|
})
|
|
])
|
|
}
|
|
|
|
/// 선택 업데이트 안내
|
|
func setSelectUpdate (action: CurrentValueSubject<String?, Never>) -> AlertData {
|
|
return AlertData(title: "업데이트 안내",
|
|
body: """
|
|
앱 최신 버전이 새로 나왔습니다.
|
|
지금 업데이트 하시겠어요?
|
|
""",
|
|
button: [
|
|
ButtonType(name: "지금 업데이트", role: .cancel,
|
|
function: {
|
|
action.send("updateNow")
|
|
}),
|
|
ButtonType(name: "나중에", role: .none,
|
|
function: {
|
|
action.send("updateLater")
|
|
}),
|
|
])
|
|
}
|
|
|
|
/// 네트워크 문제 발생 시
|
|
func setErrorNetwork() -> AlertData {
|
|
return AlertData(title: "네트워크 오류", body: "네트워크가 불안정합니다.\n확인 후 다시 시도해주세요.",
|
|
button: [
|
|
ButtonType(name: "확인", role: .cancel, function: nil)
|
|
])
|
|
}
|
|
|
|
/// 서버에서 발생한 크리티컬한 오류 - 앱 종료가 최선
|
|
func setServerError(action: CurrentValueSubject<String?, Never>) -> AlertData {
|
|
return AlertData(title: "시스템 오류", body: "시스템이 정상적이지 않습니다. \n확인 후 다시 시도해주세요.",
|
|
button: [
|
|
ButtonType(name: "확인", role: .cancel,
|
|
function: {
|
|
printLog("alertAction 'exit' send 실행됨")
|
|
action.send("exit")
|
|
})
|
|
])
|
|
}
|
|
|
|
/// 로그인 문제 발생
|
|
func setErrorLogin() -> AlertData {
|
|
return AlertData(title: "로그인",
|
|
body: """
|
|
ID 와 비밀번호가 올바르지 않습니다.
|
|
확인 후 다시 시도해주세요.
|
|
""",
|
|
button: [
|
|
ButtonType(name: "확인", role: .cancel, function: nil)
|
|
])
|
|
}
|
|
|
|
}
|
|
|