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
cf8f3803
Commit
cf8f3803
authored
Apr 28, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented subscription to NWS notifications.
parent
6358be94
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
8 deletions
+35
-8
1Weather/Coordinators/DeeplinksRouter.swift
+7
-0
1Weather/Model/LocationManager.swift
+14
-4
1Weather/Network/PushNotificationsManager.swift
+14
-4
No files found.
1Weather/Coordinators/DeeplinksRouter.swift
View file @
cf8f3803
...
...
@@ -138,6 +138,13 @@ class DeeplinksRouter {
}
}
public
func
openAlerts
()
{
DispatchQueue
.
main
.
async
{
self
.
log
.
info
(
"open Alerts"
)
self
.
appCoordinator
.
openNotifications
()
}
}
public
func
openPrecipitation
()
{
DispatchQueue
.
main
.
async
{
self
.
log
.
info
(
"open Precipitation"
)
...
...
1Weather/Model/LocationManager.swift
View file @
cf8f3803
...
...
@@ -23,6 +23,7 @@ public class LocationManager {
private
let
healthSource
:
HealthSource
private
let
fipsSource
:
FIPSSource
public
let
nwsAlertsManager
:
NWSAlertsManager
private
let
pushNotificationsManager
:
PushNotificationsManager
private
let
storage
:
Storage
private
var
defaultLocation
=
Location
(
deviceLocation
:
false
,
coordinates
:
.
init
(
latitude
:
37.3230
,
longitude
:
-
122.0322
),
// Cupertino
...
...
@@ -156,16 +157,18 @@ public class LocationManager {
healthSource
:
BlendHealthSource
(),
nwsAlertsManager
:
NWSAlertsManager
(),
fipsSource
:
BlendFIPSSource
(),
pushNotificationsManager
:
PushNotificationsManager
.
shared
,
storage
:
DelayedSaveStorage
(
storage
:
CoreDataStorage
(),
delay
:
2
))
public
let
maxLocationsCount
=
12
public
init
(
weatherUpdateSource
:
WeatherSource
,
healthSource
:
HealthSource
,
nwsAlertsManager
:
NWSAlertsManager
,
fipsSource
:
FIPSSource
,
storage
:
Storage
)
{
public
init
(
weatherUpdateSource
:
WeatherSource
,
healthSource
:
HealthSource
,
nwsAlertsManager
:
NWSAlertsManager
,
fipsSource
:
FIPSSource
,
pushNotificationsManager
:
PushNotificationsManager
,
storage
:
Storage
)
{
self
.
weatherUpdateSource
=
weatherUpdateSource
self
.
healthSource
=
healthSource
self
.
deviceLocationMonitor
=
DeviceLocationMonitor
()
self
.
nwsAlertsManager
=
nwsAlertsManager
self
.
fipsSource
=
fipsSource
self
.
pushNotificationsManager
=
pushNotificationsManager
self
.
storage
=
storage
self
.
deviceLocationMonitor
.
delegate
=
self
...
...
@@ -209,17 +212,21 @@ public class LocationManager {
updateNotifications
(
for
:
location
)
getFipsIfNeeded
(
for
:
location
)
}
pushNotificationsManager
.
updateNwsSubscriptions
(
for
:
locations
)
}
public
func
getFipsIfNeeded
(
for
location
:
Location
)
{
if
location
.
fipsCode
==
nil
{
fipsSource
.
getFipsCode
(
for
:
location
)
{
[
weak
self
]
(
fipsCode
)
in
if
let
fipsCode
=
fipsCode
{
self
?
.
makeChanges
(
to
:
location
,
in
:
"getF
ips"
)
{
(
location
)
->
Location
in
self
?
.
makeChanges
(
to
:
location
,
in
:
"getF
IPS"
,
changes
:
{
(
location
)
->
Location
in
var
updatedLocation
=
location
updatedLocation
.
fipsCode
=
fipsCode
return
updatedLocation
}
},
completion
:
{
[
weak
self
]
in
guard
let
self
=
self
else
{
return
}
self
.
pushNotificationsManager
.
updateNwsSubscriptions
(
for
:
self
.
locations
)
})
}
}
}
...
...
@@ -339,8 +346,11 @@ public class LocationManager {
}
}
private
func
makeChanges
(
to
location
:
Location
,
in
operation
:
String
,
changes
:
@escaping
(
Location
)
->
Location
)
{
private
func
makeChanges
(
to
location
:
Location
,
in
operation
:
String
,
changes
:
@escaping
(
Location
)
->
Location
,
completion
:
(()
->
())?
=
nil
)
{
DispatchQueue
.
main
.
async
{
defer
{
completion
?()
}
if
let
indexToUpdate
=
self
.
locations
.
firstIndex
(
where
:
{
$0
==
location
})
{
self
.
locations
[
indexToUpdate
]
=
changes
(
self
.
locations
[
indexToUpdate
])
}
...
...
1Weather/Network/PushNotificationsManager.swift
View file @
cf8f3803
...
...
@@ -9,7 +9,7 @@
import
Foundation
import
MoEngage
class
PushNotificationsManager
:
NSObject
{
public
class
PushNotificationsManager
:
NSObject
{
// MARK: - Private
private
let
log
=
Logger
(
componentName
:
"PushNotificationsManager"
)
...
...
@@ -41,9 +41,16 @@ class PushNotificationsManager: NSObject {
}
}
private
var
lastSetFIPSList
=
""
public
func
updateNwsSubscriptions
(
for
locations
:
[
Location
])
{
let
fipsCodes
=
locations
.
compactMap
{
$0
.
fipsCode
}
MoEngage
.
sharedInstance
()
.
setUserAttribute
(
fipsCodes
.
joined
(
separator
:
","
),
forKey
:
"FIPS_LIST"
)
let
newFipsList
=
fipsCodes
.
joined
(
separator
:
","
)
if
newFipsList
!=
lastSetFIPSList
{
log
.
info
(
"Set FIPS_LIST to '
\(
newFipsList
)
'"
)
lastSetFIPSList
=
newFipsList
}
MoEngage
.
sharedInstance
()
.
setUserAttribute
(
newFipsList
,
forKey
:
"FIPS_LIST"
)
}
public
func
set
(
pushToken
:
Data
)
{
...
...
@@ -59,6 +66,7 @@ extension PushNotificationsManager: UNUserNotificationCenterDelegate {
case
mainScreen
=
"com.handmark.expressweather.ui.activities.mainactivity"
case
detailsScreen
=
"com.handmark.expressweather.ui.activities.weatherdetailsactivity"
case
videosScreen
=
"com.handmark.expressweather.ui.activities.videodetailsactivity"
case
alertsScreen
=
"com.handmark.expressweather.ui.activities.alertactivity"
}
private
func
makeMoEngageDeeplinkUrl
(
from
response
:
UNNotificationResponse
)
->
URL
?
{
...
...
@@ -147,17 +155,19 @@ extension PushNotificationsManager: UNUserNotificationCenterDelegate {
default
:
log
.
error
(
"MoEngage push: Unknown launch screen id:
\(
launchScreenId
)
"
)
}
case
.
alertsScreen
:
router
.
openAlerts
()
}
}
}
func
userNotificationCenter
(
_
center
:
UNUserNotificationCenter
,
didReceive
response
:
UNNotificationResponse
,
withCompletionHandler
completionHandler
:
@escaping
()
->
Void
)
{
public
func
userNotificationCenter
(
_
center
:
UNUserNotificationCenter
,
didReceive
response
:
UNNotificationResponse
,
withCompletionHandler
completionHandler
:
@escaping
()
->
Void
)
{
MoEngage
.
sharedInstance
()
.
userNotificationCenter
(
center
,
didReceive
:
response
)
// not sure we should call it for PushPin notifications, too
handleMoEngageDeeplinks
(
for
:
response
)
completionHandler
()
}
func
userNotificationCenter
(
_
center
:
UNUserNotificationCenter
,
willPresent
notification
:
UNNotification
,
withCompletionHandler
completionHandler
:
@escaping
(
UNNotificationPresentationOptions
)
->
Void
)
{
public
func
userNotificationCenter
(
_
center
:
UNUserNotificationCenter
,
willPresent
notification
:
UNNotification
,
withCompletionHandler
completionHandler
:
@escaping
(
UNNotificationPresentationOptions
)
->
Void
)
{
if
UIApplication
.
shared
.
applicationState
==
.
active
{
analytics
(
log
:
.
ANALYTICS_PUSH_RECEIVED
)
...
...
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