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
c1a15102
Commit
c1a15102
authored
Aug 31, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove access to UIApplication.shared in widgets shared with widget, since it's banned.
parent
46de2356
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
47 deletions
+52
-47
1Weather/AppDelegate.swift
+40
-7
1Weather/UI/View controllers/Settings/SettingsViewController.swift
+2
-1
OneWeatherCore/OneWeatherCore.xcodeproj/project.pbxproj
+0
-4
OneWeatherCore/OneWeatherCore/Extensions/UIApplication+Settings.swift
+0
-22
OneWeatherCore/OneWeatherCore/Model/DeviceLocationMonitor.swift
+1
-1
OneWeatherCore/OneWeatherCore/Settings/Settings.swift
+9
-12
No files found.
1Weather/AppDelegate.swift
View file @
c1a15102
...
@@ -32,6 +32,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
...
@@ -32,6 +32,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
private
let
appsFlyer
=
AppsFlyerLib
.
shared
()
private
let
appsFlyer
=
AppsFlyerLib
.
shared
()
private
let
appsFlyerLog
=
Logger
(
componentName
:
"AppsFlyer"
)
private
let
appsFlyerLog
=
Logger
(
componentName
:
"AppsFlyer"
)
private
let
log
=
Logger
(
componentName
:
"AppDelegate"
)
private
let
log
=
Logger
(
componentName
:
"AppDelegate"
)
private
let
settings
=
Settings
.
shared
private
enum
FirstOpenSource
:
String
{
private
enum
FirstOpenSource
:
String
{
case
icon
=
"Icon"
case
icon
=
"Icon"
...
@@ -40,6 +41,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
...
@@ -40,6 +41,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
func
application
(
_
application
:
UIApplication
,
didFinishLaunchingWithOptions
launchOptions
:
[
UIApplication
.
LaunchOptionsKey
:
Any
]?)
->
Bool
{
func
application
(
_
application
:
UIApplication
,
didFinishLaunchingWithOptions
launchOptions
:
[
UIApplication
.
LaunchOptionsKey
:
Any
]?)
->
Bool
{
settings
.
appDelegate
=
self
settings
.
delegate
.
add
(
delegate
:
self
)
ThemeManager
.
refreshAppearance
()
ThemeManager
.
refreshAppearance
()
UserDefaults
.
migrateUserDefaultsToAppGroupsIfNeeded
()
UserDefaults
.
migrateUserDefaultsToAppGroupsIfNeeded
()
...
@@ -116,17 +119,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
...
@@ -116,17 +119,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
#endif
#endif
logAppLaunchEvents
(
launchOptions
:
launchOptions
)
logAppLaunchEvents
(
launchOptions
:
launchOptions
)
if
let
widgetPromotionTriggerCount
=
Settings
.
shared
.
widgetPromotionTriggerCount
{
if
let
widgetPromotionTriggerCount
=
settings
.
widgetPromotionTriggerCount
{
if
widgetPromotionTriggerCount
>=
0
{
if
widgetPromotionTriggerCount
>=
0
{
Settings
.
shared
.
widgetPromotionTriggerCount
=
widgetPromotionTriggerCount
-
1
settings
.
widgetPromotionTriggerCount
=
widgetPromotionTriggerCount
-
1
}
}
}
}
else
{
else
{
if
CCPAHelper
.
shared
.
isNewUser
{
if
CCPAHelper
.
shared
.
isNewUser
{
Settings
.
shared
.
widgetPromotionTriggerCount
=
2
settings
.
widgetPromotionTriggerCount
=
2
}
}
else
{
else
{
Settings
.
shared
.
widgetPromotionTriggerCount
=
0
settings
.
widgetPromotionTriggerCount
=
0
}
}
}
}
return
true
return
true
...
@@ -167,8 +170,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
...
@@ -167,8 +170,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
private
func
logAppLaunchEvents
(
launchOptions
:
[
UIApplication
.
LaunchOptionsKey
:
Any
]?)
{
private
func
logAppLaunchEvents
(
launchOptions
:
[
UIApplication
.
LaunchOptionsKey
:
Any
]?)
{
let
settings
=
Settings
.
shared
if
settings
.
firstOpenDate
==
nil
&&
CCPAHelper
.
shared
.
isNewUser
{
if
settings
.
firstOpenDate
==
nil
&&
CCPAHelper
.
shared
.
isNewUser
{
var
firstOpenSource
=
FirstOpenSource
.
icon
var
firstOpenSource
=
FirstOpenSource
.
icon
if
launchOptions
?[
.
remoteNotification
]
!=
nil
{
if
launchOptions
?[
.
remoteNotification
]
!=
nil
{
...
@@ -183,7 +184,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
...
@@ -183,7 +184,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
if
settings
.
d3RetentionDate
==
nil
{
if
settings
.
d3RetentionDate
==
nil
{
if
let
userQualifiedDate
=
Settings
.
shared
.
userQualifiedDate
{
if
let
userQualifiedDate
=
settings
.
userQualifiedDate
{
let
timeSinceQualified
=
Date
()
.
timeIntervalSince
(
userQualifiedDate
)
let
timeSinceQualified
=
Date
()
.
timeIntervalSince
(
userQualifiedDate
)
let
day
=
TimeInterval
(
3600
*
24
)
let
day
=
TimeInterval
(
3600
*
24
)
if
timeSinceQualified
>=
3
*
day
&&
timeSinceQualified
<
6
*
day
{
if
timeSinceQualified
>=
3
*
day
&&
timeSinceQualified
<
6
*
day
{
...
@@ -278,3 +279,35 @@ extension AppDelegate: DeepLinkDelegate {
...
@@ -278,3 +279,35 @@ extension AppDelegate: DeepLinkDelegate {
router
.
open
(
url
:
url
)
router
.
open
(
url
:
url
)
}
}
}
}
extension
AppDelegate
:
SettingsDelegate
{
func
settingsDidChange
()
{
DispatchQueue
.
main
.
async
{
// accessing appTheme right away causes a crash, because settingsDidChange is posted right after it was modified
if
#available(iOS 13, *)
{
switch
self
.
settings
.
appTheme
{
case
.
light
:
UIApplication
.
shared
.
keyWindow
?
.
overrideUserInterfaceStyle
=
.
light
case
.
dark
:
UIApplication
.
shared
.
keyWindow
?
.
overrideUserInterfaceStyle
=
.
dark
case
.
system
:
UIApplication
.
shared
.
keyWindow
?
.
overrideUserInterfaceStyle
=
.
unspecified
}
}
}
}
}
extension
AppDelegate
:
SettingsAppDelegate
{
func
openDeviceSettings
()
{
guard
let
bundleIdentifier
=
Bundle
.
main
.
bundleIdentifier
,
let
appSettingsURL
=
URL
(
string
:
UIApplication
.
openSettingsURLString
+
bundleIdentifier
)
else
{
assert
(
false
,
"Failed to create settings URL from:
\(
UIApplication
.
openSettingsURLString
)
"
)
return
}
UIApplication
.
shared
.
open
(
appSettingsURL
)
}
}
1Weather/UI/View controllers/Settings/SettingsViewController.swift
View file @
c1a15102
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
//
//
import
UIKit
import
UIKit
import
OneWeatherCore
import
OneWeatherAnalytics
import
OneWeatherAnalytics
class
SettingsViewController
:
UIViewController
{
class
SettingsViewController
:
UIViewController
{
...
@@ -173,7 +174,7 @@ extension SettingsViewController: UITableViewDelegate {
...
@@ -173,7 +174,7 @@ extension SettingsViewController: UITableViewDelegate {
case
.
other
:
case
.
other
:
switch
settingsCellFactory
.
rowTypeAt
(
indexPath
:
indexPath
)
{
switch
settingsCellFactory
.
rowTypeAt
(
indexPath
:
indexPath
)
{
case
.
locationAccess
:
case
.
locationAccess
:
UIApplication
.
open
Settings
()
Settings
.
shared
.
openDevice
Settings
()
default
:
default
:
break
break
}
}
...
...
OneWeatherCore/OneWeatherCore.xcodeproj/project.pbxproj
View file @
c1a15102
...
@@ -57,7 +57,6 @@
...
@@ -57,7 +57,6 @@
CD615FC32655295C00B717DB
/* Dimension+Name.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD615FB02655293100B717DB
/* Dimension+Name.swift */
;
};
CD615FC32655295C00B717DB
/* Dimension+Name.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD615FB02655293100B717DB
/* Dimension+Name.swift */
;
};
CD615FC42655295C00B717DB
/* UnitPressure+Atmosphere.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD615FB12655293100B717DB
/* UnitPressure+Atmosphere.swift */
;
};
CD615FC42655295C00B717DB
/* UnitPressure+Atmosphere.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD615FB12655293100B717DB
/* UnitPressure+Atmosphere.swift */
;
};
CD615FC52655295C00B717DB
/* CLAuthorizationStatus+Localized.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD615FB22655293100B717DB
/* CLAuthorizationStatus+Localized.swift */
;
};
CD615FC52655295C00B717DB
/* CLAuthorizationStatus+Localized.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD615FB22655293100B717DB
/* CLAuthorizationStatus+Localized.swift */
;
};
CD615FC62655295C00B717DB
/* UIApplication+Settings.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD615FB32655293100B717DB
/* UIApplication+Settings.swift */
;
};
CD6C22F026677E0200D75659
/* PushNotificationsManagerProtocol.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD6C22EF26677E0200D75659
/* PushNotificationsManagerProtocol.swift */
;
};
CD6C22F026677E0200D75659
/* PushNotificationsManagerProtocol.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD6C22EF26677E0200D75659
/* PushNotificationsManagerProtocol.swift */
;
};
CD71B9C6265E629D00803DBB
/* String+NewLine.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD71B9C5265E629D00803DBB
/* String+NewLine.swift */
;
};
CD71B9C6265E629D00803DBB
/* String+NewLine.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD71B9C5265E629D00803DBB
/* String+NewLine.swift */
;
};
CD8E48A526651414008E7F8D
/* NWSCurrentEventsReponse.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD8E48A426651414008E7F8D
/* NWSCurrentEventsReponse.swift */
;
};
CD8E48A526651414008E7F8D
/* NWSCurrentEventsReponse.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD8E48A426651414008E7F8D
/* NWSCurrentEventsReponse.swift */
;
};
...
@@ -151,7 +150,6 @@
...
@@ -151,7 +150,6 @@
CD615FB02655293100B717DB
/* Dimension+Name.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
"Dimension+Name.swift"
;
sourceTree
=
"<group>"
;
};
CD615FB02655293100B717DB
/* Dimension+Name.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
"Dimension+Name.swift"
;
sourceTree
=
"<group>"
;
};
CD615FB12655293100B717DB
/* UnitPressure+Atmosphere.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
"UnitPressure+Atmosphere.swift"
;
sourceTree
=
"<group>"
;
};
CD615FB12655293100B717DB
/* UnitPressure+Atmosphere.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
"UnitPressure+Atmosphere.swift"
;
sourceTree
=
"<group>"
;
};
CD615FB22655293100B717DB
/* CLAuthorizationStatus+Localized.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
"CLAuthorizationStatus+Localized.swift"
;
sourceTree
=
"<group>"
;
};
CD615FB22655293100B717DB
/* CLAuthorizationStatus+Localized.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
"CLAuthorizationStatus+Localized.swift"
;
sourceTree
=
"<group>"
;
};
CD615FB32655293100B717DB
/* UIApplication+Settings.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
"UIApplication+Settings.swift"
;
sourceTree
=
"<group>"
;
};
CD615FCD265529DE00B717DB
/* Settings.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Settings.swift
;
sourceTree
=
"<group>"
;
};
CD615FCD265529DE00B717DB
/* Settings.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Settings.swift
;
sourceTree
=
"<group>"
;
};
CD615FCE265529DE00B717DB
/* DefaultSettingsFactory.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
DefaultSettingsFactory.swift
;
sourceTree
=
"<group>"
;
};
CD615FCE265529DE00B717DB
/* DefaultSettingsFactory.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
DefaultSettingsFactory.swift
;
sourceTree
=
"<group>"
;
};
CD615FCF265529DE00B717DB
/* DefaultSettings.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
DefaultSettings.swift
;
sourceTree
=
"<group>"
;
};
CD615FCF265529DE00B717DB
/* DefaultSettings.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
DefaultSettings.swift
;
sourceTree
=
"<group>"
;
};
...
@@ -378,7 +376,6 @@
...
@@ -378,7 +376,6 @@
CD615FB02655293100B717DB
/* Dimension+Name.swift */
,
CD615FB02655293100B717DB
/* Dimension+Name.swift */
,
CD615FB12655293100B717DB
/* UnitPressure+Atmosphere.swift */
,
CD615FB12655293100B717DB
/* UnitPressure+Atmosphere.swift */
,
CD615FB22655293100B717DB
/* CLAuthorizationStatus+Localized.swift */
,
CD615FB22655293100B717DB
/* CLAuthorizationStatus+Localized.swift */
,
CD615FB32655293100B717DB
/* UIApplication+Settings.swift */
,
CD71B9C5265E629D00803DBB
/* String+NewLine.swift */
,
CD71B9C5265E629D00803DBB
/* String+NewLine.swift */
,
CE3A112626CD3CDE00D925C7
/* UserDefaults+OneWeather.swift */
,
CE3A112626CD3CDE00D925C7
/* UserDefaults+OneWeather.swift */
,
);
);
...
@@ -670,7 +667,6 @@
...
@@ -670,7 +667,6 @@
CD615FC32655295C00B717DB
/* Dimension+Name.swift in Sources */
,
CD615FC32655295C00B717DB
/* Dimension+Name.swift in Sources */
,
CD615FC42655295C00B717DB
/* UnitPressure+Atmosphere.swift in Sources */
,
CD615FC42655295C00B717DB
/* UnitPressure+Atmosphere.swift in Sources */
,
CD615FC52655295C00B717DB
/* CLAuthorizationStatus+Localized.swift in Sources */
,
CD615FC52655295C00B717DB
/* CLAuthorizationStatus+Localized.swift in Sources */
,
CD615FC62655295C00B717DB
/* UIApplication+Settings.swift in Sources */
,
CEFE85202694C4BC003C67D3
/* DefaultSmartText.swift in Sources */
,
CEFE85202694C4BC003C67D3
/* DefaultSmartText.swift in Sources */
,
CD8E48A526651414008E7F8D
/* NWSCurrentEventsReponse.swift in Sources */
,
CD8E48A526651414008E7F8D
/* NWSCurrentEventsReponse.swift in Sources */
,
CD427D19266F5DCE00B4350A
/* ShortsSource.swift in Sources */
,
CD427D19266F5DCE00B4350A
/* ShortsSource.swift in Sources */
,
...
...
OneWeatherCore/OneWeatherCore/Extensions/UIApplication+Settings.swift
deleted
100644 → 0
View file @
46de2356
//
// UIApplication+Settings.swift
// 1Weather
//
// Created by Dmitry Stepanets on 02.04.2021.
//
import
UIKit
public
extension
UIApplication
{
static
func
openSettings
()
{
guard
let
bundleIdentifier
=
Bundle
.
main
.
bundleIdentifier
,
let
appSettingsURL
=
URL
(
string
:
UIApplication
.
openSettingsURLString
+
bundleIdentifier
)
else
{
assert
(
false
,
"Failed to create settings URL from:
\(
UIApplication
.
openSettingsURLString
)
"
)
return
}
UIApplication
.
shared
.
open
(
appSettingsURL
)
}
}
OneWeatherCore/OneWeatherCore/Model/DeviceLocationMonitor.swift
View file @
c1a15102
...
@@ -174,7 +174,7 @@ internal class DeviceLocationMonitor: NSObject {
...
@@ -174,7 +174,7 @@ internal class DeviceLocationMonitor: NSObject {
let
alertGoToSettings
=
UIAlertController
(
title
:
"location.goToSettings.title"
.
localized
(),
message
:
text
,
preferredStyle
:
.
alert
)
let
alertGoToSettings
=
UIAlertController
(
title
:
"location.goToSettings.title"
.
localized
(),
message
:
text
,
preferredStyle
:
.
alert
)
let
actionGoToSettings
=
UIAlertAction
(
title
:
"location.goToSettings.goToSettingsAction"
.
localized
(),
style
:
.
default
)
{(
_
)
in
let
actionGoToSettings
=
UIAlertAction
(
title
:
"location.goToSettings.goToSettingsAction"
.
localized
(),
style
:
.
default
)
{(
_
)
in
UIApplication
.
open
Settings
()
Settings
.
shared
.
openDevice
Settings
()
completion
(
.
denied
)
completion
(
.
denied
)
}
}
...
...
OneWeatherCore/OneWeatherCore/Settings/Settings.swift
View file @
c1a15102
...
@@ -12,6 +12,10 @@ public protocol SettingsDelegate: AnyObject {
...
@@ -12,6 +12,10 @@ public protocol SettingsDelegate: AnyObject {
func
settingsDidChange
()
func
settingsDidChange
()
}
}
public
protocol
SettingsAppDelegate
:
AnyObject
{
func
openDeviceSettings
()
}
public
enum
AppTheme
:
Int
{
public
enum
AppTheme
:
Int
{
case
light
=
0
case
light
=
0
case
dark
case
dark
...
@@ -32,6 +36,7 @@ public enum AppTheme: Int {
...
@@ -32,6 +36,7 @@ public enum AppTheme: Int {
public
class
Settings
{
public
class
Settings
{
public
static
let
shared
=
Settings
()
public
static
let
shared
=
Settings
()
public
let
delegate
=
MulticastDelegate
<
SettingsDelegate
>
()
public
let
delegate
=
MulticastDelegate
<
SettingsDelegate
>
()
public
weak
var
appDelegate
:
SettingsAppDelegate
?
private
init
()
{}
private
init
()
{}
@UserDefaultsBasicValue(key: "app_theme", userDefaults: UserDefaults.appDefaults)
@UserDefaultsBasicValue(key: "app_theme", userDefaults: UserDefaults.appDefaults)
...
@@ -43,24 +48,16 @@ public class Settings {
...
@@ -43,24 +48,16 @@ public class Settings {
}
}
set
{
set
{
_appTheme
=
newValue
.
rawValue
_appTheme
=
newValue
.
rawValue
if
#available(iOS 13, *)
{
switch
newValue
{
case
.
light
:
UIApplication
.
shared
.
keyWindow
?
.
overrideUserInterfaceStyle
=
.
light
case
.
dark
:
UIApplication
.
shared
.
keyWindow
?
.
overrideUserInterfaceStyle
=
.
dark
case
.
system
:
UIApplication
.
shared
.
keyWindow
?
.
overrideUserInterfaceStyle
=
.
unspecified
}
}
Settings
.
shared
.
delegate
.
invoke
{
(
delegate
)
in
Settings
.
shared
.
delegate
.
invoke
{
(
delegate
)
in
delegate
.
settingsDidChange
()
delegate
.
settingsDidChange
()
}
}
}
}
}
}
public
func
openDeviceSettings
()
{
appDelegate
?
.
openDeviceSettings
()
}
@UserDefaultsUnitValue(key: "temperature_type", userDefaults: UserDefaults.appDefaults)
@UserDefaultsUnitValue(key: "temperature_type", userDefaults: UserDefaults.appDefaults)
public
var
temperatureType
=
DefaultSettingsFactory
()
.
getSettings
()
.
temperatureType
public
var
temperatureType
=
DefaultSettingsFactory
()
.
getSettings
()
.
temperatureType
...
...
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