Skip to content

Commit

Permalink
Update iOS code
Browse files Browse the repository at this point in the history
  • Loading branch information
raae7742 committed Jun 4, 2023
1 parent 2f15d29 commit a50857e
Show file tree
Hide file tree
Showing 86 changed files with 3,349 additions and 1,693 deletions.
17 changes: 17 additions & 0 deletions CPR2U-iOS/.github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Make Plist Files
run: |
echo '
<?xml version="1.0" encoding="UTF-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>baseURL</key>
<string>$secrets.BASE_URL</string>
<key>googleMapsAPIKey</key>
<string>$secrets.MAPS_API_KEY</string>
</dict>
</plist>
' >> ./CPR2U/CPR2U/Private.plist
echo '
' >> ./CPR2U/CPR2U/GoogleService-Info.plist
- name: Build Xcode
run: |
pod install --repo-update --clean-install --project-directory=CPR2U/
Expand Down
100 changes: 66 additions & 34 deletions CPR2U-iOS/CPR2U/CPR2U.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

38 changes: 8 additions & 30 deletions CPR2U-iOS/CPR2U/CPR2U/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// https://stackoverflow.com/questions/28938660/how-to-lock-orientation-of-one-view-controller-to-portrait-mode-only-in-swift
var orientationLock = UIInterfaceOrientationMask.portrait
var isNotificationHandled = false

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return self.orientationLock
Expand All @@ -24,13 +25,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

registerForRemoteNotifications()

// MARK: FCM Setting
FirebaseApp.configure()
Messaging.messaging().delegate = self

UNUserNotificationCenter.current().delegate = self
Messaging.messaging().delegate = self

let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
Expand All @@ -57,32 +56,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let deviceTokenString = deviceToken.map { String(format: "%02x", $0) }.joined()
Messaging.messaging().apnsToken = deviceToken
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
}

private func registerForRemoteNotifications() {

// 1. 푸시 center (유저에게 권한 요청 용도)
let center = UNUserNotificationCenter.current()
center.delegate = self // push처리에 대한 delegate - UNUserNotificationCenterDelegate
let options: UNAuthorizationOptions = [.alert, .sound, .badge]
center.requestAuthorization(options: options) { (granted, error) in

guard granted else {
return
}

DispatchQueue.main.async {
// 2. APNs에 디바이스 토큰 등록
UIApplication.shared.registerForRemoteNotifications()
}
}
}
}

extension AppDelegate: MessagingDelegate {
Expand All @@ -91,6 +66,7 @@ extension AppDelegate: MessagingDelegate {
let dataDict:[String: String] = ["token": fcmToken]
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
DeviceTokenManager.deviceToken = fcmToken

}
}

Expand All @@ -100,12 +76,14 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .badge, .sound])
completionHandler([.banner, .sound])
}

// push를 탭한 경우 처리
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let url = response.notification.request.content.userInfo
let userInfo = response.notification.request.content.userInfo
print(response.notification)
NotificationCenter.default.post(name: Notification.Name("ShowCallerPage"), object: nil, userInfo: userInfo)
}
}

1 change: 0 additions & 1 deletion CPR2U-iOS/CPR2U/CPR2U/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
let window = UIWindow(windowScene: windowScene)

self.window = window
// let navVC = UINavigationController(rootViewController: EducationMainViewController())
let vc = AutoLoginViewController()
window.rootViewController = vc
window.backgroundColor = .white
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "map.png",
"filename" : "check.png",
"idiom" : "universal",
"scale" : "1x"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "ic_fail_heart.png",
"filename" : "check_badge.png",
"idiom" : "universal",
"scale" : "1x"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "exclamation_mark.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "time_check.png",
"filename" : "heart_fail.png",
"idiom" : "universal",
"scale" : "1x"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "success_heart.png",
"filename" : "heart_success.png",
"idiom" : "universal",
"scale" : "1x"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "map_black.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified CPR2U-iOS/CPR2U/CPR2U/Assets.xcassets/person.imageset/person.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "pose_guideline.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified CPR2U-iOS/CPR2U/CPR2U/Assets.xcassets/time.imageset/time.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "time_black.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "x_mark.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified CPR2U-iOS/CPR2U/CPR2U/Component/Sound/CPR_Posture_Sound.mp3
Binary file not shown.
2 changes: 2 additions & 0 deletions CPR2U-iOS/CPR2U/CPR2U/Data/DTO/Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ struct SMSCodeResult: Codable {
}

struct NicknameVerifyResult: Codable {}

struct LogOutResult: Codable {}
1 change: 0 additions & 1 deletion CPR2U-iOS/CPR2U/CPR2U/Data/DTO/Education.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ struct UserInfo: Codable {
let angel_status: Int
let progress_percent: Double
let is_lecture_completed: Int
let last_lecture_title: String
let is_quiz_completed: Int
let is_posture_completed: Int
let days_left_until_expiration: Int?
Expand Down
66 changes: 47 additions & 19 deletions CPR2U-iOS/CPR2U/CPR2U/Scene/Call/CallViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,38 @@ import Foundation
import GoogleMaps

final class CallViewModel: OutputOnlyViewModelType {
@Published private(set)var callerListInfo: CallerListInfo?
@Published private(set)var dispatcherCount: Int?

private var callManager: CallManager
private var dispatchManager: DispatchManager

private var mapManager: MapManager
private var currentLocation: CLLocationCoordinate2D?

private var currentLocationAddress = CurrentValueSubject<String, Never>("Unable")
var callerList: CurrentValueSubject<CallerListInfo, Never>?

private var callId: Int?
private let iscalled = CurrentValueSubject<Bool, Never>(false)
private let isDispatchEnd = CurrentValueSubject<Bool, Never>(false)

var timer: Timer.TimerPublisher?

init() {
callManager = CallManager(service: APIManager())
mapManager = MapManager()
Task {
try await receiveCallerList()
}
dispatchManager = DispatchManager(service: APIManager())
receiveCallerList()
setLocation()
}

struct Output {
let isCalled: CurrentValueSubject<Bool, Never>
let currentLocationAddress: CurrentValueSubject<String, Never>?
let callerList: CurrentValueSubject<CallerListInfo, Never>?
}

func transform() -> Output {
return Output(isCalled: iscalled, currentLocationAddress: currentLocationAddress, callerList: callerList)
return Output(isCalled: iscalled, currentLocationAddress: currentLocationAddress)
}

func isCallSucceed() {
Expand All @@ -64,16 +66,13 @@ final class CallViewModel: OutputOnlyViewModelType {
currentLocationAddress.send(str)
}

func receiveCallerList() async throws -> CallerListInfo? {
let result = Task { () -> CallerListInfo? in
func receiveCallerList() {
Task {
let callResult = try await callManager.getCallerList()

guard let list = callResult.data else { return nil }
callerList = CurrentValueSubject(list)
print(callerList)
return list
guard let list = callResult.data else { return }
callerListInfo = list
}
return try await result.value
}

func callDispatcher() async throws {
Expand All @@ -94,18 +93,47 @@ final class CallViewModel: OutputOnlyViewModelType {
}
}

func countDispatcher() async throws -> Int? {
guard let callId = callId else { return nil }
func countDispatcher() {
guard let callId = callId else { return }

let result = Task { () -> Int? in
Task {
let callResult = try await callManager.countDispatcher(callId: callId)
return callResult.data?.number_of_angels
dispatcherCount = callResult.data?.number_of_angels
}

return try await result.value
}

private func updateCallId(callId: Int) {
self.callId = callId
}

func dispatchEnd(dispatchId: Int) async throws -> Bool {
let taskResult = Task { () -> Bool in
let result = try await dispatchManager.dispatchEnd(dispatchId: dispatchId)
return result.success
}
return try await taskResult.value
}

func updateDispatchEnd() {
isDispatchEnd.send(true)

}

func getDispatchEnd() -> CurrentValueSubject<Bool, Never> {
return isDispatchEnd
}
func dispatchAccept(cprCallId: Int) async throws -> (Bool, DispatchInfo?) {
let taskResult = Task { () -> (Bool, DispatchInfo?) in
let result = try await dispatchManager.dispatchAccept(cprCallId: cprCallId)
return (result.success, result.data)
}
return try await taskResult.value
}
func userReport(reportInfo: ReportInfo) async throws -> Bool {
let taskResult = Task { () -> Bool in
let result = try await dispatchManager.userReport(reportInfo: reportInfo)
return result.success
}
return try await taskResult.value
}
}
Loading

0 comments on commit a50857e

Please sign in to comment.