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
541f3a3c
Commit
541f3a3c
authored
Apr 27, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MoEngage push notifications handling.
parent
7d111caa
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
38 deletions
+41
-38
1Weather/Analytics/AnalyticsParameter.swift
+1
-0
1Weather/AppDelegate.swift
+6
-0
1Weather/Coordinators/DeeplinksRouter.swift
+1
-1
1Weather/Model/LocationManager.swift
+10
-10
1Weather/Network/PushNotificationsManager.swift
+23
-27
No files found.
1Weather/Analytics/AnalyticsParameter.swift
View file @
541f3a3c
...
...
@@ -18,4 +18,5 @@ public enum AnalyticsParameter: String {
case
ANALYTICS_KEY_PLACEMENT_NAME
=
"placement_name"
case
ANALYTICS_KEY_AD_UNIT_ID
=
"AD_PLACEMENT_ID"
case
ANALYTICS_KEY_AD_ADAPTER
=
"AD_ADAPTER"
case
ANALYTICS_KEY_PUSH_NOTIFICATION_SOURCE
=
"source"
}
1Weather/AppDelegate.swift
View file @
541f3a3c
...
...
@@ -70,11 +70,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
MoEngage
.
sharedInstance
()
.
initializeLive
(
with
:
moEngageConfig
,
andLaunchOptions
:
launchOptions
)
#endif
PushNotificationsManager
.
shared
.
registerForRemoteNotifications
()
return
true
}
func
applicationDidBecomeActive
(
_
application
:
UIApplication
)
{
LocationManager
.
shared
.
updateAllWeatherIfNeeded
()
}
func
application
(
_
application
:
UIApplication
,
didRegisterForRemoteNotificationsWithDeviceToken
deviceToken
:
Data
)
{
PushNotificationsManager
.
shared
.
set
(
pushToken
:
deviceToken
)
}
}
1Weather/Coordinators/DeeplinksRouter.swift
View file @
541f3a3c
...
...
@@ -55,7 +55,7 @@ class DeeplinksRouter {
return
false
}
p
rivate
func
parseLocation
(
from
url
:
URL
)
->
PartialLocation
?
{
p
ublic
func
parseLocation
(
from
url
:
URL
)
->
PartialLocation
?
{
guard
let
queryItems
=
URLComponents
(
url
:
url
,
resolvingAgainstBaseURL
:
false
)?
.
queryItems
else
{
return
nil
}
...
...
1Weather/Model/LocationManager.swift
View file @
541f3a3c
...
...
@@ -421,16 +421,6 @@ public class LocationManager {
}
private
func
makeLocation
(
from
partialLocation
:
PartialLocation
,
completion
:
@escaping
(
Location
?)
->
())
{
guard
let
latStr
=
partialLocation
.
lat
,
let
lonStr
=
partialLocation
.
lon
,
let
lat
=
CLLocationDegrees
(
latStr
),
let
lon
=
CLLocationDegrees
(
lonStr
)
else
{
log
.
error
(
"Geo lookup: no coordinates present:
\(
partialLocation
)
"
)
var
location
:
Location
?
=
nil
if
partialLocation
.
deviceLocation
{
log
.
debug
(
"Adding a placeholder empty device location."
)
location
=
Location
(
deviceLocation
:
true
,
timeZone
:
TimeZone
.
current
)
}
completion
(
location
)
return
}
if
let
fipsCode
=
partialLocation
.
fipsCode
{
if
let
existingLocation
=
locations
.
first
(
where
:
{
$0
.
fipsCode
==
fipsCode
})
{
completion
(
existingLocation
)
...
...
@@ -443,6 +433,16 @@ public class LocationManager {
return
}
}
guard
let
latStr
=
partialLocation
.
lat
,
let
lonStr
=
partialLocation
.
lon
,
let
lat
=
CLLocationDegrees
(
latStr
),
let
lon
=
CLLocationDegrees
(
lonStr
)
else
{
log
.
error
(
"Geo lookup: no coordinates present:
\(
partialLocation
)
"
)
var
location
:
Location
?
=
nil
if
partialLocation
.
deviceLocation
{
log
.
debug
(
"Adding a placeholder empty device location."
)
location
=
Location
(
deviceLocation
:
true
,
timeZone
:
TimeZone
.
current
)
}
completion
(
location
)
return
}
let
location
=
CLLocation
(
latitude
:
lat
,
longitude
:
lon
)
...
...
1Weather/Network/PushNotificationsManager.swift
View file @
541f3a3c
...
...
@@ -8,7 +8,7 @@
import
Foundation
import
MoEngage
/*
class
PushNotificationsManager
:
NSObject
{
// MARK: - Private
...
...
@@ -66,26 +66,28 @@ extension PushNotificationsManager: UNUserNotificationCenterDelegate {
return
nil
}
private func switchLocationIfNeeded(parsing screenData: [String: Any]?, using router: Router) {
private
func
switchLocationIfNeeded
(
parsing
screenData
:
[
String
:
Any
]?,
using
router
:
Deeplinks
Router
)
{
guard
let
screenData
=
screenData
else
{
return
}
if let cityId = screenData["location"] as? String {
let lat = screenData["lat"] as? String
let lon = screenData["lon"] as? String
if let location = WeatherUpdateManager.shared.locationFrom(cityId: cityId, lat: lat, lon: lon) {
log.info("MoEngage push: location found: \(location)")
WeatherUpdateManager.shared.addLocation(location)
}
else {
log.error("MoEngage push:Location found but couldn't be parsed.")
}
}
else {
log.debug("MoEngage push: no cityId found")
let
cityId
=
screenData
[
"location"
]
as?
String
let
lat
=
screenData
[
"lat"
]
as?
String
let
lon
=
screenData
[
"lon"
]
as?
String
let
fipsCode
=
screenData
[
"fipsCode"
]
as?
String
guard
(
lat
!=
nil
&&
lon
!=
nil
)
||
cityId
!=
nil
||
fipsCode
!=
nil
else
{
log
.
debug
(
"MoEngage push: no location data found"
)
return
}
let
newLoc
=
GeoNamesPlace
()
newLoc
.
latitude
=
lat
newLoc
.
longitude
=
lon
newLoc
.
optionalCityId
=
cityId
newLoc
.
fipsCode
=
fipsCode
LocationManager
.
shared
.
addIfNeeded
(
partialLocation
:
newLoc
,
selectLocation
:
true
)
log
.
info
(
"MoEngage push: location found:
\(
newLoc
)
"
)
}
private
func
handleMoEngageDeeplinks
(
for
response
:
UNNotificationResponse
)
{
...
...
@@ -98,12 +100,7 @@ extension PushNotificationsManager: UNUserNotificationCenterDelegate {
log
.
info
(
"MoEngage push received:
\(
userInfo
)
"
)
guard let tabBar = TabBarController.viewController else {
log.error("No tab bar found to initialize Router")
return
}
let router = Router(tabBar: tabBar)
let
router
=
DeeplinksRouter
()
if
let
moEngageUrl
=
makeMoEngageDeeplinkUrl
(
from
:
response
)
{
router
.
open
(
url
:
moEngageUrl
)
}
...
...
@@ -135,7 +132,7 @@ extension PushNotificationsManager: UNUserNotificationCenterDelegate {
case
"0"
:
router
.
openToday
()
case
"1"
:
router.openForecast(
detailType
: nil)
router
.
openForecast
(
timePeriod
:
nil
)
case
"2"
:
router
.
openPrecipitation
()
case
"3"
:
...
...
@@ -151,7 +148,6 @@ extension PushNotificationsManager: UNUserNotificationCenterDelegate {
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
guard !pushPinManager.processPushPinNotification(response) else { return }
handleMoEngageDeeplinks
(
for
:
response
)
completionHandler
()
}
...
...
@@ -159,13 +155,13 @@ extension PushNotificationsManager: UNUserNotificationCenterDelegate {
func
userNotificationCenter
(
_
center
:
UNUserNotificationCenter
,
willPresent
notification
:
UNNotification
,
withCompletionHandler
completionHandler
:
@escaping
(
UNNotificationPresentationOptions
)
->
Void
)
{
if
UIApplication
.
shared
.
applicationState
==
.
active
{
analytics
LogEvent(
ANALYTICS_PUSH_RECEIVED)
analytics
(
log
:
.
ANALYTICS_PUSH_RECEIVED
)
}
else
{
analytics
LogEvent(ANALYTICS_PUSH_SELECTED, params: ["source"
: "background"])
analytics
(
log
:
.
ANALYTICS_PUSH_SELECTED
,
params
:
[
.
ANALYTICS_KEY_PUSH_NOTIFICATION_SOURCE
:
"background"
])
}
log
.
debug
(
"Got a push notification:
\(
notification
.
request
.
content
.
userInfo
)
"
);
completionHandler
([
.
sound
,
.
alert
])
}
}
*/
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