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
da0f8907
Commit
da0f8907
authored
Apr 29, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Config: disable NWS Alerts subscription through MoEngage.
parent
3009c5ef
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
20 deletions
+61
-20
1Weather/Ads/Configuration/AdConfig.swift
+4
-4
1Weather/Configuration/LocalConfig.plist
+2
-0
1Weather/Model/CCPA/CCPAHelper.swift
+6
-2
1Weather/Network/ConfigManager.swift
+17
-6
1Weather/Network/PushNotificationsManager.swift
+32
-8
No files found.
1Weather/Ads/Configuration/AdConfig.swift
View file @
da0f8907
...
...
@@ -8,7 +8,7 @@
import
UIKit
struct
AdConfig
:
Codable
{
public
struct
AdConfig
:
Codable
{
private
static
let
defaultA9MaxCachedPerPlacement
:
UInt
=
2
var
adsEnabled
:
Bool
...
...
@@ -46,7 +46,7 @@ struct AdConfig: Codable {
a9MaxCachedPerPlacement
=
AdConfig
.
defaultA9MaxCachedPerPlacement
}
init
(
from
decoder
:
Decoder
)
throws
{
public
init
(
from
decoder
:
Decoder
)
throws
{
let
container
=
try
decoder
.
container
(
keyedBy
:
CodingKeys
.
self
)
adsEnabled
=
try
container
.
decode
(
Bool
.
self
,
forKey
:
.
adsEnabled
)
...
...
@@ -71,7 +71,7 @@ struct AdConfig: Codable {
}
}
func
encode
(
to
encoder
:
Encoder
)
throws
{
public
func
encode
(
to
encoder
:
Encoder
)
throws
{
var
container
=
encoder
.
container
(
keyedBy
:
CodingKeys
.
self
)
try
container
.
encode
(
adsEnabled
,
forKey
:
.
adsEnabled
)
try
container
.
encode
(
a9RefreshRate
,
forKey
:
.
a9RefreshRate
)
...
...
@@ -86,7 +86,7 @@ public enum AdType: String, Codable {
}
extension
AdConfig
:
Equatable
{
static
func
==
(
lhs
:
AdConfig
,
rhs
:
AdConfig
)
->
Bool
{
public
static
func
==
(
lhs
:
AdConfig
,
rhs
:
AdConfig
)
->
Bool
{
return
lhs
.
adsEnabled
==
rhs
.
adsEnabled
&&
lhs
.
a9RefreshRate
==
rhs
.
a9RefreshRate
&&
lhs
.
placements
==
rhs
.
placements
&&
...
...
1Weather/Configuration/LocalConfig.plist
View file @
da0f8907
...
...
@@ -4,6 +4,8 @@
<
d
i
c
t
>
<
k
e
y
>
search_screen_popular_cities
<
/k
e
y
>
<
string
>
[
{
&
quot
;
lat
&
quot
;
:
&
quot
;
40.7127
&
quot
;
,&
quot
;
lon
&
quot
;
:
&
quot
;
-74.006
&
quot
;
,&
quot
;
city
&
quot
;
:
&
quot
;
New
York
&
quot
;
,&
quot
;
state
&
quot
;
:
&
quot
;
New
York
&
quot
;
,&
quot
;
stateCode
&
quot
;
:
&
quot
;
NY
&
quot
;
,&
quot
;
country
&
quot
;
:
&
quot
;
United
States
of
America
&
quot
;
,&
quot
;
countryCode
&
quot
;
:
&
quot
;
US
&
quot
;
,&
quot
;
order
&
quot
;
:1
}
,
{
&
quot
;
lat
&
quot
;
:
&
quot
;
41.8756
&
quot
;
,&
quot
;
lon
&
quot
;
:
&
quot
;
-87.6244
&
quot
;
,&
quot
;
city
&
quot
;
:
&
quot
;
Chicago
&
quot
;
,&
quot
;
state
&
quot
;
:
&
quot
;
Illinois
&
quot
;
,&
quot
;
stateCode
&
quot
;
:
&
quot
;
IL
&
quot
;
,&
quot
;
country
&
quot
;
:
&
quot
;
United
States
of
America
&
quot
;
,&
quot
;
countryCode
&
quot
;
:
&
quot
;
US
&
quot
;
,&
quot
;
order
&
quot
;
:2
}
,
{
&
quot
;
lat
&
quot
;
:
&
quot
;
29.7589
&
quot
;
,&
quot
;
lon
&
quot
;
:
&
quot
;
-95.3677
&
quot
;
,&
quot
;
city
&
quot
;
:
&
quot
;
Houston
&
quot
;
,&
quot
;
state
&
quot
;
:
&
quot
;
Texas
&
quot
;
,&
quot
;
stateCode
&
quot
;
:
&
quot
;
TX
&
quot
;
,&
quot
;
country
&
quot
;
:
&
quot
;
United
States
of
America
&
quot
;
,&
quot
;
countryCode
&
quot
;
:
&
quot
;
US
&
quot
;
,&
quot
;
order
&
quot
;
:3
}
,
{
&
quot
;
lat
&
quot
;
:
&
quot
;
34.0537
&
quot
;
,&
quot
;
lon
&
quot
;
:
&
quot
;
-118.243
&
quot
;
,&
quot
;
city
&
quot
;
:
&
quot
;
Los
Angeles
&
quot
;
,&
quot
;
state
&
quot
;
:
&
quot
;
California
&
quot
;
,&
quot
;
stateCode
&
quot
;
:
&
quot
;
CA
&
quot
;
,&
quot
;
country
&
quot
;
:
&
quot
;
United
States
of
America
&
quot
;
,&
quot
;
countryCode
&
quot
;
:
&
quot
;
US
&
quot
;
,&
quot
;
order
&
quot
;
:4
}
,
{
&
quot
;
lat
&
quot
;
:
&
quot
;
29.4246
&
quot
;
,&
quot
;
lon
&
quot
;
:
&
quot
;
-98.4951
&
quot
;
,&
quot
;
city
&
quot
;
:
&
quot
;
San
Antonio
&
quot
;
,&
quot
;
state
&
quot
;
:
&
quot
;
Texas
&
quot
;
,&
quot
;
stateCode
&
quot
;
:
&
quot
;
TX
&
quot
;
,&
quot
;
country
&
quot
;
:
&
quot
;
United
States
of
America
&
quot
;
,&
quot
;
countryCode
&
quot
;
:
&
quot
;
US
&
quot
;
,&
quot
;
order
&
quot
;
:5
}
,
{
&
quot
;
lat
&
quot
;
:
&
quot
;
39.7683
&
quot
;
,&
quot
;
lon
&
quot
;
:
&
quot
;
-86.1584
&
quot
;
,&
quot
;
city
&
quot
;
:
&
quot
;
Indianapolis
&
quot
;
,&
quot
;
state
&
quot
;
:
&
quot
;
Indiana
&
quot
;
,&
quot
;
stateCode
&
quot
;
:
&
quot
;
IN
&
quot
;
,&
quot
;
country
&
quot
;
:
&
quot
;
United
States
of
America
&
quot
;
,&
quot
;
countryCode
&
quot
;
:
&
quot
;
US
&
quot
;
,&
quot
;
order
&
quot
;
:6
}
,
{
&
quot
;
lat
&
quot
;
:
&
quot
;
39.9527
&
quot
;
,&
quot
;
lon
&
quot
;
:
&
quot
;
-75.1635
&
quot
;
,&
quot
;
city
&
quot
;
:
&
quot
;
Philadelphia
&
quot
;
,&
quot
;
state
&
quot
;
:
&
quot
;
Pennsylvania
&
quot
;
,&
quot
;
stateCode
&
quot
;
:
&
quot
;
PA
&
quot
;
,&
quot
;
country
&
quot
;
:
&
quot
;
United
States
of
America
&
quot
;
,&
quot
;
countryCode
&
quot
;
:
&
quot
;
US
&
quot
;
,&
quot
;
order
&
quot
;
:7
}
,
{
&
quot
;
lat
&
quot
;
:
&
quot
;
36.1673
&
quot
;
,&
quot
;
lon
&
quot
;
:
&
quot
;
-115.149
&
quot
;
,&
quot
;
city
&
quot
;
:
&
quot
;
Las
Vegas
&
quot
;
,&
quot
;
state
&
quot
;
:
&
quot
;
Nevada
&
quot
;
,&
quot
;
stateCode
&
quot
;
:
&
quot
;
NV
&
quot
;
,&
quot
;
country
&
quot
;
:
&
quot
;
United
States
of
America
&
quot
;
,&
quot
;
countryCode
&
quot
;
:
&
quot
;
US
&
quot
;
,&
quot
;
order
&
quot
;
:8
}
,
{
&
quot
;
lat
&
quot
;
:
&
quot
;
39.9623
&
quot
;
,&
quot
;
lon
&
quot
;
:
&
quot
;
-83.0007
&
quot
;
,&
quot
;
city
&
quot
;
:
&
quot
;
Columbus
&
quot
;
,&
quot
;
state
&
quot
;
:
&
quot
;
Ohio
&
quot
;
,&
quot
;
stateCode
&
quot
;
:
&
quot
;
OH
&
quot
;
,&
quot
;
country
&
quot
;
:
&
quot
;
United
States
of
America
&
quot
;
,&
quot
;
countryCode
&
quot
;
:
&
quot
;
US
&
quot
;
,&
quot
;
order
&
quot
;
:9
}
,
{
&
quot
;
lat
&
quot
;
:
&
quot
;
30.3322
&
quot
;
,&
quot
;
lon
&
quot
;
:
&
quot
;
-81.6557
&
quot
;
,&
quot
;
city
&
quot
;
:
&
quot
;
Jacksonville
&
quot
;
,&
quot
;
state
&
quot
;
:
&
quot
;
Florida
&
quot
;
,&
quot
;
stateCode
&
quot
;
:
&
quot
;
FL
&
quot
;
,&
quot
;
country
&
quot
;
:
&
quot
;
United
States
of
America
&
quot
;
,&
quot
;
countryCode
&
quot
;
:
&
quot
;
US
&
quot
;
,&
quot
;
order
&
quot
;
:10
}
]
<
/string
>
<
k
e
y
>
nws_alerts_via_moengage_enabled
<
/k
e
y
>
<
tru
e
/
>
<
k
e
y
>
ads_config_ios
<
/k
e
y
>
<
string
>{
&
quot
;
//": "1Weather iOS built in config. Override it in the Firebase console. Note that the ads_enabled: true is needed for correct initialization after receiving a proper config.",
...
...
1Weather/Model/CCPA/CCPAHelper.swift
View file @
da0f8907
...
...
@@ -25,6 +25,7 @@ fileprivate let DEVICE_TYPE = "IOS"
class
CCPAHelper
{
public
static
let
shared
=
CCPAHelper
()
private
static
let
googleRDPKey
=
"gad_rdp"
private
let
configManager
:
ConfigManager
?
/// Call this method in applicationDidFinishLaunching.
public
func
onAppLaunch
()
{
...
...
@@ -35,6 +36,10 @@ class CCPAHelper {
log
.
debug
(
"CCPA Helper: isNewUser:
\(
isNewUser
?
"true"
:
"false"
)
"
)
}
init
(
configManager
:
ConfigManager
?
=
ConfigManager
.
shared
)
{
self
.
configManager
=
configManager
}
public
var
isNewUser
:
Bool
{
locationPermissionsUndeterminedOnLaunch
&&
!
hadLocationsOnLaunch
}
...
...
@@ -91,7 +96,7 @@ class CCPAHelper {
private
var
lastSuccessfullUpdateDate
:
Date
?
private
var
minimumTimeSinceLastSuccessfulUpdate
:
TimeInterval
{
return
CCPAHelper
.
defaultMinimumTimeSinceLastSuccessfulUpdate
configManager
?
.
config
.
ccpaUpdateInterval
??
CCPAHelper
.
defaultMinimumTimeSinceLastSuccessfulUpdate
}
private
func
registerAppAfterDelay
()
{
...
...
@@ -405,5 +410,4 @@ struct CCPAStatusBody: Codable, CustomDebugStringConvertible {
return
"
\(
ccpaCollectData
)
\(
privacyPolicyVersion
)
"
}
}
1Weather/Network/ConfigManager.swift
View file @
da0f8907
...
...
@@ -10,26 +10,29 @@ import Foundation
import
Firebase
import
FirebaseRemoteConfig
struct
AppConfig
:
Codable
{
public
struct
AppConfig
:
Codable
{
let
popularCities
:
[
GeoNamesPlace
]?
let
adConfig
:
AdConfig
let
ccpaUpdateInterval
:
TimeInterval
?
let
nwsAlertsViaMoEngageEnabled
:
Bool
init
(
popularCities
:
[
GeoNamesPlace
]?,
adConfig
:
AdConfig
,
ccpaUpdateInterval
:
TimeInterval
?)
{
init
(
popularCities
:
[
GeoNamesPlace
]?,
adConfig
:
AdConfig
,
ccpaUpdateInterval
:
TimeInterval
?
,
nwsAlertsViaMoEngageEnabled
:
Bool
)
{
self
.
popularCities
=
popularCities
self
.
adConfig
=
adConfig
self
.
ccpaUpdateInterval
=
ccpaUpdateInterval
self
.
nwsAlertsViaMoEngageEnabled
=
nwsAlertsViaMoEngageEnabled
}
}
protocol
ConfigManagerDelegate
{
p
ublic
p
rotocol
ConfigManagerDelegate
{
func
dataUpdated
(
by
configManager
:
ConfigManager
)
}
class
ConfigManager
{
public
class
ConfigManager
{
private
static
let
adConfigKey
=
"ads_config_ios"
private
static
let
popularCitiesConfigKey
=
"search_screen_popular_cities"
private
static
let
ccpaUpdateIntervalConfigKey
=
"ccpa_update_interval_ios"
private
static
let
nwsAlertsViaMoEngageEnabledKey
=
"nws_alerts_via_moengage_enabled"
private
let
delegates
=
MulticastDelegate
<
ConfigManagerDelegate
>
()
...
...
@@ -45,7 +48,7 @@ class ConfigManager {
public
static
let
shared
=
ConfigManager
()
public
var
config
:
AppConfig
=
AppConfig
(
popularCities
:
nil
,
adConfig
:
AdConfig
(),
ccpaUpdateInterval
:
nil
)
public
var
config
:
AppConfig
=
AppConfig
(
popularCities
:
nil
,
adConfig
:
AdConfig
(),
ccpaUpdateInterval
:
nil
,
nwsAlertsViaMoEngageEnabled
:
true
)
public
func
updateConfig
()
{
log
.
info
(
"update config"
)
...
...
@@ -73,6 +76,10 @@ class ConfigManager {
delegates
.
add
(
delegate
:
delegate
)
}
public
func
remove
(
delegate
:
ConfigManagerDelegate
)
{
delegates
.
remove
(
delegate
:
delegate
)
}
private
func
parseConfigFromFirebase
(
source
:
String
)
{
log
.
info
(
"Got config from
\(
source
)
"
)
var
configErrors
=
[
Error
]()
...
...
@@ -110,8 +117,12 @@ class ConfigManager {
ccpaUpdateInterval
=
ccpaUpdateIntervalConfigValue
.
numberValue
.
doubleValue
}
let
nwsAlertsViaMoEngageEnabledValue
=
remoteConfig
.
configValue
(
forKey
:
ConfigManager
.
nwsAlertsViaMoEngageEnabledKey
)
let
nwsAlertsViaMoEngageEnabled
=
nwsAlertsViaMoEngageEnabledValue
.
boolValue
DispatchQueue
.
main
.
async
{
self
.
config
=
AppConfig
(
popularCities
:
popularCities
,
adConfig
:
adConfig
,
ccpaUpdateInterval
:
ccpaUpdateInterval
)
self
.
config
=
AppConfig
(
popularCities
:
popularCities
,
adConfig
:
adConfig
,
ccpaUpdateInterval
:
ccpaUpdateInterval
,
nwsAlertsViaMoEngageEnabled
:
nwsAlertsViaMoEngageEnabled
)
self
.
notifyAboutConfigUpdate
()
DispatchQueue
.
global
()
.
async
{
let
encoder
=
JSONEncoder
()
...
...
1Weather/Network/PushNotificationsManager.swift
View file @
da0f8907
...
...
@@ -13,15 +13,23 @@ public class PushNotificationsManager: NSObject {
// MARK: - Private
private
let
log
=
Logger
(
componentName
:
"PushNotificationsManager"
)
private
let
configManager
:
ConfigManager
// MARK: - Public
public
override
init
()
{
public
static
let
shared
=
PushNotificationsManager
()
public
init
(
configManager
:
ConfigManager
=
ConfigManager
.
shared
)
{
self
.
configManager
=
configManager
super
.
init
()
self
.
configManager
.
add
(
delegate
:
self
)
UNUserNotificationCenter
.
current
()
.
delegate
=
self
}
public
static
let
shared
=
PushNotificationsManager
()
deinit
{
self
.
configManager
.
remove
(
delegate
:
self
)
}
// TODO: forced re-register on timeout
...
...
@@ -41,16 +49,26 @@ public class PushNotificationsManager: NSObject {
}
}
private
var
lastSetFIPSList
=
""
private
var
lastSetFIPSList
:
String
?
=
""
private
func
updateNwsSubscriptions
(
with
fipsList
:
String
?)
{
if
configManager
.
config
.
nwsAlertsViaMoEngageEnabled
{
if
fipsList
!=
lastSetFIPSList
{
log
.
info
(
"Set FIPS_LIST to '
\(
fipsList
??
""
)
'"
)
lastSetFIPSList
=
fipsList
}
}
else
{
log
.
info
(
"Set FIPS_LIST to nil, because nwsAlertsViaMoEngage are disabled via config."
)
lastSetFIPSList
=
nil
}
MoEngage
.
sharedInstance
()
.
setUserAttribute
(
lastSetFIPSList
,
forKey
:
"FIPS_LIST"
)
}
public
func
updateNwsSubscriptions
(
for
locations
:
[
Location
])
{
let
fipsCodes
=
locations
.
compactMap
{
$0
.
fipsCode
}
let
newFipsList
=
fipsCodes
.
joined
(
separator
:
","
)
if
newFipsList
!=
lastSetFIPSList
{
log
.
info
(
"Set FIPS_LIST to '
\(
newFipsList
)
'"
)
lastSetFIPSList
=
newFipsList
}
MoEngage
.
sharedInstance
()
.
setUserAttribute
(
newFipsList
,
forKey
:
"FIPS_LIST"
)
updateNwsSubscriptions
(
with
:
newFipsList
)
}
public
func
set
(
pushToken
:
Data
)
{
...
...
@@ -60,6 +78,12 @@ public class PushNotificationsManager: NSObject {
}
}
extension
PushNotificationsManager
:
ConfigManagerDelegate
{
public
func
dataUpdated
(
by
configManager
:
ConfigManager
)
{
updateNwsSubscriptions
(
with
:
lastSetFIPSList
)
}
}
extension
PushNotificationsManager
:
UNUserNotificationCenterDelegate
{
private
enum
MoEngageScreenName
:
String
{
...
...
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