Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
45366f35
Commit
45366f35
authored
May 07, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Error handling for failed reverse geocoding.
parent
1b2e8abb
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
10 deletions
+57
-10
1Weather/Coordinators/DeeplinksRouter.swift
+5
-1
1Weather/Model/LocationManager.swift
+33
-5
1Weather/Network/PushNotificationsManager.swift
+5
-1
1Weather/Resources/en.lproj/Localizable.strings
+2
-0
1Weather/Storage/LegacyMigrationManager.swift
+3
-1
1Weather/UI/View controllers/Locations/LocationsViewModel.swift
+9
-2
No files found.
1Weather/Coordinators/DeeplinksRouter.swift
View file @
45366f35
...
@@ -92,7 +92,11 @@ class DeeplinksRouter {
...
@@ -92,7 +92,11 @@ class DeeplinksRouter {
log
.
debug
(
"Parsed path:
\(
parsedComponent
.
rawValue
)
"
)
log
.
debug
(
"Parsed path:
\(
parsedComponent
.
rawValue
)
"
)
if
let
location
=
parseLocation
(
from
:
url
)
{
if
let
location
=
parseLocation
(
from
:
url
)
{
log
.
debug
(
"Location found:
\(
location
)
"
)
log
.
debug
(
"Location found:
\(
location
)
"
)
locationManager
.
addIfNeeded
(
partialLocation
:
location
,
selectLocation
:
true
)
locationManager
.
addIfNeeded
(
partialLocation
:
location
,
selectLocation
:
true
)
{
success
in
if
!
success
{
self
.
log
.
error
(
"Failed to add / switch the location"
)
}
}
}
}
else
{
else
{
log
.
debug
(
"No location."
)
log
.
debug
(
"No location."
)
...
...
1Weather/Model/LocationManager.swift
View file @
45366f35
...
@@ -227,7 +227,11 @@ public class LocationManager {
...
@@ -227,7 +227,11 @@ public class LocationManager {
if
self
.
deviceLocationMonitor
.
hasLocationPermissions
{
if
self
.
deviceLocationMonitor
.
hasLocationPermissions
{
if
locations
.
first
?
.
deviceLocation
!=
true
{
if
locations
.
first
?
.
deviceLocation
!=
true
{
if
let
lastKnownLocation
=
self
.
deviceLocationMonitor
.
lastKnownLocation
{
if
let
lastKnownLocation
=
self
.
deviceLocationMonitor
.
lastKnownLocation
{
self
.
addIfNeeded
(
partialLocation
:
lastKnownLocation
,
selectLocation
:
false
)
self
.
addIfNeeded
(
partialLocation
:
lastKnownLocation
,
selectLocation
:
false
)
{
success
in
if
!
success
{
self
.
log
.
error
(
"Failed to add / switch the location"
)
}
}
}
}
}
}
}
}
...
@@ -252,7 +256,11 @@ public class LocationManager {
...
@@ -252,7 +256,11 @@ public class LocationManager {
}
}
for
location
:
PartialLocation
in
legacyLocations
{
for
location
:
PartialLocation
in
legacyLocations
{
self
.
addIfNeeded
(
partialLocation
:
location
,
selectLocation
:
location
.
selected
??
false
)
self
.
addIfNeeded
(
partialLocation
:
location
,
selectLocation
:
location
.
selected
??
false
)
{
success
in
if
!
success
{
self
.
log
.
error
(
"Failed to migrate location:
\(
location
.
nameForDisplay
)
"
)
}
}
}
}
self
.
loadedLocations
=
true
self
.
loadedLocations
=
true
...
@@ -471,7 +479,7 @@ public class LocationManager {
...
@@ -471,7 +479,7 @@ public class LocationManager {
updateEverythingIfNeeded
()
updateEverythingIfNeeded
()
}
}
public
func
addIfNeeded
(
partialLocation
:
PartialLocation
,
selectLocation
:
Bool
)
{
public
func
addIfNeeded
(
partialLocation
:
PartialLocation
,
selectLocation
:
Bool
,
completion
:
@escaping
(
Bool
)
->
()
)
{
if
let
location
=
partialLocation
as?
Location
{
if
let
location
=
partialLocation
as?
Location
{
addIfNeeded
(
location
:
location
,
selectLocation
:
selectLocation
)
addIfNeeded
(
location
:
location
,
selectLocation
:
selectLocation
)
}
}
...
@@ -479,8 +487,12 @@ public class LocationManager {
...
@@ -479,8 +487,12 @@ public class LocationManager {
makeLocation
(
from
:
partialLocation
)
{
(
location
)
in
makeLocation
(
from
:
partialLocation
)
{
(
location
)
in
onMain
{
[
weak
self
]
in
onMain
{
[
weak
self
]
in
if
let
location
=
location
{
if
let
location
=
location
{
completion
(
true
)
self
?
.
addIfNeeded
(
location
:
location
,
selectLocation
:
selectLocation
)
self
?
.
addIfNeeded
(
location
:
location
,
selectLocation
:
selectLocation
)
}
}
else
{
completion
(
false
)
}
}
}
}
}
}
}
...
@@ -513,7 +525,18 @@ public class LocationManager {
...
@@ -513,7 +525,18 @@ public class LocationManager {
deviceLocationMonitor
.
useCurrentLocation
(
requestedFrom
:
viewController
)
{
[
weak
self
]
(
result
)
in
deviceLocationMonitor
.
useCurrentLocation
(
requestedFrom
:
viewController
)
{
[
weak
self
]
(
result
)
in
switch
result
{
switch
result
{
case
.
success
(
let
location
):
case
.
success
(
let
location
):
self
?
.
addIfNeeded
(
partialLocation
:
location
,
selectLocation
:
true
)
self
?
.
addIfNeeded
(
partialLocation
:
location
,
selectLocation
:
true
)
{
success
in
if
!
success
{
self
?
.
log
.
error
(
"Failed to add / switch the location to the current one. Will try again in a second"
)
DispatchQueue
.
main
.
asyncAfter
(
deadline
:
.
now
()
+
1
)
{
self
?
.
addIfNeeded
(
partialLocation
:
location
,
selectLocation
:
true
,
completion
:
{
success
in
if
!
success
{
self
?
.
log
.
error
(
"Still failed to add the current location."
)
}
})
}
}
}
completion
(
.
success
)
completion
(
.
success
)
case
.
denied
:
case
.
denied
:
completion
(
.
denied
)
completion
(
.
denied
)
...
@@ -580,6 +603,7 @@ public class LocationManager {
...
@@ -580,6 +603,7 @@ public class LocationManager {
result
?
.
countryCode
=
placemark
.
isoCountryCode
result
?
.
countryCode
=
placemark
.
isoCountryCode
result
?
.
region
=
partialLocation
.
region
??
placemark
.
administrativeArea
result
?
.
region
=
partialLocation
.
region
??
placemark
.
administrativeArea
result
?
.
zip
=
placemark
.
postalCode
result
?
.
zip
=
placemark
.
postalCode
result
?
.
nickname
=
partialLocation
.
nickname
self
.
log
.
info
(
"Geo lookup got location:
\(
result
?
.
description
??
"-"
)
"
)
self
.
log
.
info
(
"Geo lookup got location:
\(
result
?
.
description
??
"-"
)
"
)
}
}
...
@@ -598,7 +622,11 @@ public class LocationManager {
...
@@ -598,7 +622,11 @@ public class LocationManager {
extension
LocationManager
:
DeviceLocationMonitorDelegate
{
extension
LocationManager
:
DeviceLocationMonitorDelegate
{
func
deviceLocationMonitor
(
_
monitor
:
DeviceLocationMonitor
,
didUpdateLocation
newLocation
:
PartialLocation
)
{
func
deviceLocationMonitor
(
_
monitor
:
DeviceLocationMonitor
,
didUpdateLocation
newLocation
:
PartialLocation
)
{
log
.
debug
(
"device location updated: (
\(
newLocation
.
lat
??
"-"
)
;
\(
newLocation
.
lon
??
"-"
)
)"
)
log
.
debug
(
"device location updated: (
\(
newLocation
.
lat
??
"-"
)
;
\(
newLocation
.
lon
??
"-"
)
)"
)
addIfNeeded
(
partialLocation
:
newLocation
,
selectLocation
:
false
)
addIfNeeded
(
partialLocation
:
newLocation
,
selectLocation
:
false
)
{
success
in
if
!
success
{
self
.
log
.
error
(
"Failed to update the current location."
)
}
}
}
}
func
deviceLocationMonitor
(
_
monitor
:
DeviceLocationMonitor
,
authorizationStatusChanged
locationIsAllowed
:
Bool
)
{
func
deviceLocationMonitor
(
_
monitor
:
DeviceLocationMonitor
,
authorizationStatusChanged
locationIsAllowed
:
Bool
)
{
...
...
1Weather/Network/PushNotificationsManager.swift
View file @
45366f35
...
@@ -134,7 +134,11 @@ extension PushNotificationsManager: UNUserNotificationCenterDelegate {
...
@@ -134,7 +134,11 @@ extension PushNotificationsManager: UNUserNotificationCenterDelegate {
newLoc
.
longitude
=
lon
newLoc
.
longitude
=
lon
newLoc
.
optionalCityId
=
cityId
newLoc
.
optionalCityId
=
cityId
newLoc
.
fipsCode
=
fipsCode
newLoc
.
fipsCode
=
fipsCode
LocationManager
.
shared
.
addIfNeeded
(
partialLocation
:
newLoc
,
selectLocation
:
true
)
LocationManager
.
shared
.
addIfNeeded
(
partialLocation
:
newLoc
,
selectLocation
:
true
)
{
success
in
if
!
success
{
self
.
log
.
error
(
"Failed to add / switch the location"
)
}
}
log
.
info
(
"MoEngage push: location found:
\(
newLoc
)
"
)
log
.
info
(
"MoEngage push: location found:
\(
newLoc
)
"
)
}
}
...
...
1Weather/Resources/en.lproj/Localizable.strings
View file @
45366f35
...
@@ -138,6 +138,8 @@
...
@@ -138,6 +138,8 @@
"search.error.maxLocationWarning" = "To keep your 1Weather running in tip-top shape, please limit the number of locations to %@";
"search.error.maxLocationWarning" = "To keep your 1Weather running in tip-top shape, please limit the number of locations to %@";
"search.error.deleteError" = "Failed to delete location.";
"search.error.deleteError" = "Failed to delete location.";
"search.accessibility.tapToSelectLocation" = "Tap to select this location";
"search.accessibility.tapToSelectLocation" = "Tap to select this location";
"search.error.title" = "Error";
"search.error.addError.message" = "An error occurred while adding the location. Please, make sure you have an internet connection and try again.";
//Location
//Location
"location.servicesAreTurnedOff" = "System location services are turned off.";
"location.servicesAreTurnedOff" = "System location services are turned off.";
...
...
1Weather/Storage/LegacyMigrationManager.swift
View file @
45366f35
...
@@ -44,7 +44,9 @@ class LegacyMigrationManager {
...
@@ -44,7 +44,9 @@ class LegacyMigrationManager {
var
fipsCode
:
String
?
var
fipsCode
:
String
?
let
optionalCityId
:
String
?
=
nil
let
optionalCityId
:
String
?
=
nil
var
nickname
:
String
?
var
nickname
:
String
?
let
nameForDisplay
:
String
=
""
var
nameForDisplay
:
String
{
"
\(
countryName
??
""
)
:
\(
region
??
""
)
:
\(
cityName
??
""
)
(
\(
nickname
??
""
)
) – @
\(
lat
??
""
)
;
\(
lon
??
""
)
; isDevice:
\(
deviceLocation
)
"
}
}
}
private
var
lastMigrationResult
:
MigrationResult
?
{
private
var
lastMigrationResult
:
MigrationResult
?
{
...
...
1Weather/UI/View controllers/Locations/LocationsViewModel.swift
View file @
45366f35
...
@@ -197,9 +197,16 @@ public class LocationsViewModel {
...
@@ -197,9 +197,16 @@ public class LocationsViewModel {
self
.
delegate
?
.
viewModelError
(
model
:
self
,
title
:
nil
,
message
:
"search.error.maxLocationWarning"
.
localized
())
self
.
delegate
?
.
viewModelError
(
model
:
self
,
title
:
nil
,
message
:
"search.error.maxLocationWarning"
.
localized
())
return
return
}
}
locationManager
.
addIfNeeded
(
partialLocation
:
city
,
selectLocation
:
true
)
locationManager
.
addIfNeeded
(
partialLocation
:
city
,
selectLocation
:
true
)
{
success
in
if
success
{
self
.
delegate
?
.
viewModelDidSelectCity
(
model
:
self
)
self
.
delegate
?
.
viewModelDidSelectCity
(
model
:
self
)
}
}
else
{
self
.
delegate
?
.
viewModelError
(
model
:
self
,
title
:
"search.error.title"
.
localized
(),
message
:
"search.error.addError.message"
.
localized
())
}
}
}
func
delete
(
city
:
PartialLocation
)
{
func
delete
(
city
:
PartialLocation
)
{
guard
let
location
=
city
as?
Location
else
{
guard
let
location
=
city
as?
Location
else
{
...
@@ -207,7 +214,7 @@ public class LocationsViewModel {
...
@@ -207,7 +214,7 @@ public class LocationsViewModel {
return
return
}
}
if
!
locationManager
.
remove
(
location
:
location
)
{
if
!
locationManager
.
remove
(
location
:
location
)
{
self
.
delegate
?
.
viewModelError
(
model
:
self
,
title
:
"
Error"
,
message
:
"search.error.deleteError"
.
localized
())
self
.
delegate
?
.
viewModelError
(
model
:
self
,
title
:
"
search.error.title"
.
localized
()
,
message
:
"search.error.deleteError"
.
localized
())
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment