[] 회원가입 로직 추가 생성 및 헤더 관련 로직 변경 추가

This commit is contained in:
김선규 2025-03-28 17:56:33 +09:00
parent 63031172a1
commit 519fcc537c
9 changed files with 215 additions and 14 deletions

View File

@ -83,7 +83,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
//
func application(_ application: UIApplication,didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02.2hX", $1)})
@UserDefault(key: "pushToken", defaultValue: "") var pushToken
@UserDefault(key: "pushToken", defaultValue: "pushToken") var pushToken
pushToken = deviceTokenString
printLog("APNs 디바이스 푸시 토큰: \(deviceTokenString)")
//

View File

@ -261,10 +261,6 @@ struct RegisterView: View {
dropdownManager.font = .nps(size: 16)
}
// .onChange(of: dropdownManager.onSelect) { _, new in
// printLog("CHANGE: \(new)")
//
// }
}
func leftAct() {
@ -276,3 +272,18 @@ struct RegisterView: View {
}
}
struct selectPolicyView: View {
@ObservedObject var registerVM: RegisterViewModel
@ObservedObject var btnVM: ButtonViewModel
init(_ registerVM: RegisterViewModel, btnVM: ButtonViewModel) {
self.registerVM = registerVM
self.btnVM = btnVM
}
var body: some View {
HStack(spacing: 0) {
CircleBtnView(vm: btnVM, id: registerVM.policyBtn1ID)
}
}
}

View File

@ -86,13 +86,15 @@ class User: Codable {
}
// /api/v1/in/user/login ----------------
// /api/v1/in/user/register ----------------
class User_Token: Codable {
let token: String?
let refresh: String?
// let bids: [String]
}
// /api/v1/in/member/academy ----------------
class AcademyName: Codable {
let bid: String?

View File

@ -8,9 +8,9 @@
import Foundation
enum SNSLoginType{
case Kakao
case Apple
enum SNSLoginType: String{
case Apple = "ST00"
case Kakao = "ST01"
}
struct SNSID: Codable {

View File

@ -7,6 +7,11 @@
import SwiftUI
import Combine
//
//import AVFoundation
//import Photos
//import CoreLocation
//import UserNotifications
class AppViewModel: ObservableObject {
// public static let shared = AppViewModel()
@ -21,9 +26,11 @@ class AppViewModel: ObservableObject {
///
let alertAction = CurrentValueSubject<String?, Never>(nil)
var apiManager: APIManager = APIManager()
var permissionManager = PermissionManager()
// private init() {
//
// init() {
// permissionManager.location
// }
//
}

View File

@ -18,8 +18,14 @@ class RegisterViewModel: ObservableObject {
self.responseValue = (type, snsID)
}
@UserDefault(key: "token", defaultValue: "accToken") var accToken
@UserDefault(key: "refresh", defaultValue: "refreshToken") var refresh
@UserDefault(key: "header", defaultValue: "headerValue") var headerValue
@UserDefault(key: "pushToken", defaultValue: "pushToken") var pushToken
let addressBtnID = UUID()
let registerBtnID = UUID()
let policyBtn1ID = UUID()
@Published var selectDate: Date = {
let calendar = Calendar.current
@ -57,16 +63,61 @@ class RegisterViewModel: ObservableObject {
func registerUser() {
//
let birth = "\(selectDate.convertString("yyyy-MM-dd"))"
printLog("\(birth)")
if nameText != "" && emailFrontText != "" && emailTailText != "" && phoneTextSet.0 != "" && phoneTextSet.1 != "" && phoneTextSet.2 != "" {
var param: [String:Any] = [:]
param["name"] = "\(nameText)"
if changeDate { param["birth"] = "\(selectDate.convertString("yyyy-MM-dd"))"}
param["type"] = "UT02"
if let deviceId = UIDevice.current.identifierForVendor?.uuidString,
let bundleId = Bundle.main.bundleIdentifier {
param["device_id"] = "\(deviceId)"
}
param["auto_login_yn"] = false
param["login_date"] = Date()
param["push_token"] = "\(pushToken)"
param["email"] = "\(emailFrontText)@\(emailTailText)"
param["phone"] = "\(phoneTextSet.0)\(phoneTextSet.1)\(phoneTextSet.2)"
if addressText != "주소 입력" {
if addrDetailText == "" { param["address"] = "\(self.addressText)" }
else { param["address"] = "\(self.addressText) \(self.addrDetailText)"}
}
param["location_yn"] = appVM.permissionManager.checkLocationPermission()
param["camera_yn"] = appVM.permissionManager.checkCameraPermission()
param["photo_yn"] = appVM.permissionManager.checkPhotoPermission()
appVM.permissionManager.checkPushPermission(completion: { status in
param["push_yn"] = status
})
param["market_app_yn"] = true
param["market_sms_yn"] = true
param["market_email_yn"] = true
param["sns_id"] = self.responseValue.1
param["sns_type"] = self.responseValue.0.rawValue
if !changeDate || addressText == "주소 입력" {
appVM.alertData = AlertData(
title: "알림",
body: "\(changeDate ? "":"[생일]")\((addressText != "주소 입력") ? "":"[주소]")의 내용이 없습니다.\n 계속해서 진행할까요?",
button: [ButtonType(name: "확인", role: .cancel, function: nil)])
button: [
ButtonType(name: "돌아가기", role: .destructive, function: nil),
ButtonType(name: "가입하기", role: .cancel) {
self.callAPI(param)
}
]
)
appVM.showAlert.toggle()
//
} else {
self.callAPI(param)
//
}
@ -77,7 +128,42 @@ class RegisterViewModel: ObservableObject {
button: [ButtonType(name: "확인", role: .cancel, function: nil)])
appVM.showAlert.toggle()
}
}
private func callAPI(_ param: [String: Any]) {
self.appVM.apiManager.loadAPIData(
APIRequest(path: "/api/v1/in/user/register",
headers: [API_HEADER : self.headerValue],
parameters: param,
decoding: APIResponse<User_Token>.self)
)
.sink { [weak self] completion in
guard let self = self else { return }
// API
switch completion {
case .failure(let error):
printLog("\(error)")
case .finished:
break
}
} receiveValue: { [weak self] response in
guard let self = self else { return }
switch response.status.code {
case .success(let code):
if code == "000" {
if let data = response.data, let accToken = data.token, let refresh = data.refresh{
self.accToken = accToken
self.refresh = refresh
appVM.naviState.set(act: .RESET, path: .Main)
}
}
default:
break
}
}
.store(in: &cancellables)
}

View File

@ -0,0 +1,86 @@
//
// PermissionManager.swift
// AcaMate
//
// Created by TAnine on 3/28/25.
//
import Foundation
import AVFoundation
import Photos
import CoreLocation
import UserNotifications
class PermissionManager: NSObject, ObservableObject {
private let locationManager = CLLocationManager()
private var locationRequestCallback: ((CLAuthorizationStatus) -> Void)?
override init() {
super.init()
locationManager.delegate = self
}
// MARK: -
func requestPushPermission(completion: @escaping (Bool) -> Void) {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
DispatchQueue.main.async {
completion(granted)
}
}
}
// MARK: -
func requestCameraPermission(completion: @escaping (Bool) -> Void) {
AVCaptureDevice.requestAccess(for: .video) { granted in
DispatchQueue.main.async {
completion(granted)
}
}
}
// MARK: -
func requestPhotoPermission(completion: @escaping (PHAuthorizationStatus) -> Void) {
PHPhotoLibrary.requestAuthorization { status in
DispatchQueue.main.async {
completion(status)
}
}
}
// MARK: -
func requestLocationPermission(completion: @escaping (CLAuthorizationStatus) -> Void) {
locationRequestCallback = completion
locationManager.requestWhenInUseAuthorization()
}
// MARK: -
func checkPushPermission(completion: @escaping (Bool) -> Void) {
UNUserNotificationCenter.current().getNotificationSettings { settings in
DispatchQueue.main.async {
completion(settings.authorizationStatus == .authorized)
}
}
}
func checkCameraPermission() -> Bool {
return AVCaptureDevice.authorizationStatus(for: .video) == .authorized
}
func checkPhotoPermission() -> Bool {
let status = PHPhotoLibrary.authorizationStatus(for: .readWrite)
return status == .authorized || status == .limited
}
func checkLocationPermission() -> Bool {
let status = locationManager.authorizationStatus
return status == .authorizedAlways || status == .authorizedWhenInUse
}
}
extension PermissionManager: CLLocationManagerDelegate {
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
let status = manager.authorizationStatus
locationRequestCallback?(status)
locationRequestCallback = nil
}
}

View File

@ -50,5 +50,14 @@
<string>fetch</string>
<string>external-accessory</string>
</array>
<key>NSCameraUsageDescription</key>
<string>카메라 접근이 필요합니다.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>사진 앨범 접근이 필요합니다.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>앱 사용 중 위치 접근이 필요합니다.</string>
<key>NSUserTrackingUsageDescription</key>
<string>푸시 알림 권한을 요청합니다.</string>
</dict>
</plist>