Skip to content

Commit 9e05891

Browse files
authored
Merge pull request #53 from Nexters/fix/gps
fix: 노티피케이션 챌린지 중, 나갈 때만 구현
2 parents 84fba83 + 1cd2330 commit 9e05891

File tree

14 files changed

+63
-52
lines changed

14 files changed

+63
-52
lines changed

Sticky/Assets.xcassets/level_info/level_info_EN.imageset/Contents.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"images" : [
33
{
4-
"filename" : "등급정보_EN.png",
4+
"filename" : "level_info_EN.png",
55
"idiom" : "universal",
66
"scale" : "1x"
77
},
88
{
9-
"filename" : "등급정보_EN-1.png",
9+
"filename" : "level_info_EN-1.png",
1010
"idiom" : "universal",
1111
"scale" : "2x"
1212
},

Sticky/Assets.xcassets/level_info/level_info_EN.imageset/등급정보_EN-1.png renamed to Sticky/Assets.xcassets/level_info/level_info_EN.imageset/level_info_EN-1.png

File renamed without changes.

Sticky/Assets.xcassets/level_info/level_info_EN.imageset/등급정보_EN.png renamed to Sticky/Assets.xcassets/level_info/level_info_EN.imageset/level_info_EN.png

File renamed without changes.

Sticky/Assets.xcassets/level_info/level_info_KR.imageset/Contents.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"images" : [
33
{
4-
"filename" : "등급정보_KR.png",
4+
"filename" : "level_info_KR.png",
55
"idiom" : "universal",
66
"scale" : "1x"
77
},
88
{
9-
"filename" : "등급정보_KR-1.png",
9+
"filename" : "level_info_KR-1.png",
1010
"idiom" : "universal",
1111
"scale" : "2x"
1212
},

Sticky/Assets.xcassets/level_info/level_info_KR.imageset/등급정보_KR-1.png renamed to Sticky/Assets.xcassets/level_info/level_info_KR.imageset/level_info_KR-1.png

File renamed without changes.

Sticky/Assets.xcassets/level_info/level_info_KR.imageset/등급정보_KR.png renamed to Sticky/Assets.xcassets/level_info/level_info_KR.imageset/level_info_KR.png

File renamed without changes.

Sticky/Features/AppMain.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct AppMain: View {
4949
popupState.popupStyle = .fail
5050
popupState.isPresented = true
5151
challengeState.type = .notAtHome
52+
print("로케이션 나가기 - \(popupState.isPresented)")
5253
// }
5354
} else if challengeState.type == .notRunning {
5455
print("시작하지 않은 상태인데 집 밖으로 나감")

Sticky/Features/PopupMessage.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import SwiftUI
1212
struct PopupMessage: View {
1313
// MARK: Internal
1414

15+
@EnvironmentObject var popupState: PopupStateModel
1516
@Binding var isPresented: Bool
1617
@Binding var numberOfHeart: Int
1718
let message: Message
@@ -49,7 +50,7 @@ struct PopupMessage: View {
4950
)
5051

5152
Button(action: {
52-
self.isPresented = false
53+
popupState.isPresented = false
5354
self.confirmHandler()
5455
}, label: {
5556
RoundedRectangle(cornerRadius: 16)
@@ -70,7 +71,8 @@ struct PopupMessage: View {
7071
}).padding(.bottom, 8)
7172

7273
Button(action: {
73-
self.isPresented = false
74+
popupState.isPresented = false
75+
print("로케이션 나가기(Popup) - \(popupState.isPresented)")
7476
}, label: {
7577
RoundedRectangle(cornerRadius: 16)
7678
.stroke(Color.black.opacity(0.1), lineWidth: 1)

Sticky/Features/SearchAddress/Services/LocationManager.swift

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class LocationManager: NSObject, ObservableObject {
5050
// span: MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005)
5151
// )
5252
@Published var isAlways: Bool = false
53+
var challengeType: Main.ChallengeType?
5354

5455
var geofence: CLCircularRegion? {
5556
willSet {
@@ -64,7 +65,6 @@ class LocationManager: NSObject, ObservableObject {
6465
}
6566
}
6667
}
67-
6868

6969
@Published var status: CLAuthorizationStatus? {
7070
willSet { self.objectWillChange.send() }
@@ -73,20 +73,20 @@ class LocationManager: NSObject, ObservableObject {
7373
@Published var location = CLLocation() {
7474
willSet {
7575
print("LocationManager - location\(newValue) willSet")
76-
print("LocationManager - 1 : \((self.geofence?.contains(newValue.coordinate) ?? false))")
76+
print("LocationManager - 1 : \(self.geofence?.contains(newValue.coordinate) ?? false)")
7777
print("LocationManager - 2 : \(!(self.geofence?.contains(self.location.coordinate) ?? false))")
78-
print("LocationManager - 3 : \(!(geofence?.contains(newValue.coordinate) ?? false))")
78+
print("LocationManager - 3 : \(!(self.geofence?.contains(newValue.coordinate) ?? false))")
7979
print("LocationManager - 4 : \(self.geofence?.contains(self.location.coordinate) ?? false)")
80-
81-
if (self.geofence?.contains(newValue.coordinate) ?? false), !(self.geofence?.contains(self.location.coordinate) ?? false) {
80+
81+
if self.geofence?.contains(newValue.coordinate) ?? false, !(self.geofence?.contains(self.location.coordinate) ?? false) {
8282
// newValue내에 존재 && 이전Value내에 존재하지 X
8383
print("LocationManager - geofence enter")
8484
NotificationCenter.default.post(name: .enterGeofence, object: nil)
85-
} else if !(geofence?.contains(newValue.coordinate) ?? false), (self.geofence?.contains(self.location.coordinate) ?? false) {
85+
} else if !(self.geofence?.contains(newValue.coordinate) ?? false), self.geofence?.contains(self.location.coordinate) ?? false {
8686
print("LocationManager - geofence exit")
8787
NotificationCenter.default.post(name: .exitGeofence, object: nil)
8888
}
89-
89+
9090
self.objectWillChange.send()
9191
}
9292
}
@@ -142,7 +142,7 @@ extension LocationManager: CLLocationManagerDelegate {
142142
didUpdateLocations locations: [CLLocation]
143143
) {
144144
guard let location = locations.last else {
145-
print("변경된 location이 없습니다")
145+
print("LocationManager - 변경된 location이 없습니다")
146146
return
147147
}
148148
self.location = location
@@ -166,7 +166,7 @@ extension LocationManager: CLLocationManagerDelegate {
166166
챌린지 종료 카운트다운 초기화
167167
*/
168168
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
169-
print("Enter: \(self.geofence?.center)")
169+
print("LocationManager - Enter: \(self.geofence?.center)")
170170
NotificationCenter.default.post(name: .enterGeofence, object: nil)
171171
}
172172

@@ -175,23 +175,28 @@ extension LocationManager: CLLocationManagerDelegate {
175175
- 현재 위치에서 벗어남을 감지하고 n초 후 챌린지 종료 카운트 다운 및 경고
176176
*/
177177
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {
178-
print("Exit: \(self.geofence?.center)")
178+
print("LocationManager - Exit: \(self.geofence?.center)")
179179
NotificationCenter.default.post(name: .exitGeofence, object: nil)
180180
}
181181

182182
/** 현재 위치를 지오펜싱으로 영역 처리
183183
*/
184+
185+
func resetGeofence() {
186+
if let reset_geofence = self.geofence {
187+
scheduleNotification_exit(region: reset_geofence)
188+
}
189+
}
190+
184191
func setGeofenceMyHome(region: MKCoordinateRegion) {
185192
let _geofenceExit = CLCircularRegion(
186193
center: region.center,
187194
radius: 100, // 100m
188195
identifier: "MyHomeRegion1"
189196
)
190197

191-
_geofenceExit.notifyOnExit = true
192-
_geofenceExit.notifyOnEntry = true
193198
self.geofence = _geofenceExit
194-
scheduleNotification_exit(region: _geofenceExit)
199+
// scheduleNotification_exit(region: _geofenceExit)
195200
// self.locationManager.startMonitoring(for: _geofenceExit)
196201
}
197202
}
@@ -201,53 +206,38 @@ extension LocationManager: CLLocationManagerDelegate {
201206
extension LocationManager: UNUserNotificationCenterDelegate {
202207
func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) {}
203208

204-
func scheduleNotification_enter(region: CLCircularRegion) {
205-
print("asd")
206-
let center = UNUserNotificationCenter.current()
207-
208-
center.removeAllPendingNotificationRequests() // deletes pending scheduled notifications, there is a schedule limit qty
209-
210-
let content = UNMutableNotificationContent()
211-
content.title = "들어감"
212-
content.body = "Run! This zone is dangerous! :o"
213-
content.categoryIdentifier = "alarm"
214-
content.sound = UNNotificationSound.default
215-
216-
// Ex. Trigger within a timeInterval
217-
// let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
218-
219-
let trigger = UNLocationNotificationTrigger(region: region, repeats: true)
220-
221-
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
222-
self.notificationCenter.add(request)
223-
}
224-
225209
func scheduleNotification_exit(region: CLCircularRegion) {
226-
print("asd")
227210
let center = UNUserNotificationCenter.current()
228211

229212
center.removeAllPendingNotificationRequests() // deletes pending scheduled notifications, there is a schedule limit qty
230213

231214
let content = UNMutableNotificationContent()
232-
content.title = "나가기"
233-
content.body = "Run! This zone is dangerous! :o"
215+
content.title = "나갔다"
216+
content.body = "?????"
234217
content.categoryIdentifier = "alarm"
235218
content.sound = UNNotificationSound.default
236219

220+
region.notifyOnEntry = false
221+
region.notifyOnExit = true
237222
// Ex. Trigger within a timeInterval
238223
// let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
239224

240-
let trigger = UNLocationNotificationTrigger(region: region, repeats: true)
225+
let trigger = UNLocationNotificationTrigger(region: region, repeats: false)
241226

242227
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
243-
self.notificationCenter.add(request)
228+
center.add(request)
244229
}
245230

246231
func userNotificationCenter(
247232
_ center: UNUserNotificationCenter,
248233
willPresent notification: UNNotification,
249234
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
250235
) {
251-
completionHandler([.list, .badge, .sound])
236+
if self.challengeType == .running {
237+
print("로케이션 completion \(self.challengeType)")
238+
completionHandler([.banner, .list, .sound])
239+
} else {
240+
print("로케이션 \(self.challengeType)")
241+
}
252242
}
253243
}

Sticky/Features/Share/Component/CardSlide.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ struct CardSlide: View {
2424
@EnvironmentObject var user: User
2525

2626
@Binding var items: [Card]
27+
let randomBodyText_KR = ["와우! 끈기가 대단해요", "정말 대단해요!", "와 진짜 믿을수 없어"]
28+
let randomBodyText_EN = ["Exellent..!", "Is this real?", "Wow, I can't believe it.", "Unbelievable", "That's amazing", "I'm proud of you"]
29+
let randomNumber = Int.random(in: 0...5)
2730
let spacing: CGFloat = 16
2831
// 숨겨진 카드의 보여질 width
2932
let widthOfHiddenCards: CGFloat = 40 /// UIScreen.main.bounds.width - 10
@@ -131,25 +134,26 @@ struct CardSlide: View {
131134
.font(.custom("Modak", size: 80))
132135
.frame(height: 64)
133136
.padding(.bottom, 1)
137+
134138
Text("")
135139
.font(.system(size: 17, weight: .heavy, design: .default))
136140
.frame(width: 96)
137141
}
138142
.isHidden(isDayTextHidden, remove: isDayTextHidden)
143+
.foregroundColor(.white)
139144

140145
// Hour
141146
VStack {
142147
Text(String(challengeState.timeData.hour))
143148
.font(.custom("Modak", size: 80))
144149
.frame(height: 64)
145150
.padding(.bottom, 1)
146-
.foregroundColor(.white)
147151
Text("시간")
148-
.foregroundColor(.white)
149152
.font(.system(size: 17, weight: .heavy, design: .default))
150153
.frame(width: 96)
151154
}
152155
.isHidden(isHourTextHidden, remove: isHourTextHidden)
156+
.foregroundColor(.white)
153157

154158
// 얘 높이가 Text랑 달라서 그룹지어서 처리해야함
155159
// Minute
@@ -166,11 +170,13 @@ struct CardSlide: View {
166170
.frame(width: 96)
167171
}
168172
.isHidden(!isDayTextHidden, remove: !isDayTextHidden)
173+
.foregroundColor(.white)
169174
}
170175
.frame(width: 216)
171176
.padding(.top, 24)
172-
Text("body text")
177+
Text(getRandomText())
173178
.padding(.top, 24)
179+
.foregroundColor(.white)
174180
Spacer()
175181
}
176182
}.frame(width: gr.frame(in: .global).size.width, height: gr.frame(in: .global).height, alignment: /*@START_MENU_TOKEN@*/ .center/*@END_MENU_TOKEN@*/)
@@ -201,6 +207,15 @@ struct CardSlide: View {
201207
return Color.Sticky.blue
202208
}
203209
}
210+
211+
private func getRandomText() -> String{
212+
if Locale.current.regionCode == "KR"{
213+
return randomBodyText_KR[randomNumber % 3]
214+
}else{
215+
return randomBodyText_EN[randomNumber]
216+
217+
}
218+
}
204219

205220
private var level: Int {
206221
switch Tier.of(hours: (user.accumulateSeconds + challengeState.timeData.toSeconds()) / 3600).level {

0 commit comments

Comments
 (0)