Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_sdk_framework
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Manos Chorianopoulos
2024-03-04 11:14:54 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
aa2ceb5b0adc64a4054da6edc981a0defb1a3846
aa2ceb5b
1 parent
0a6864d7
fix webviewDidFocus for app kill redeisign
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
40 deletions
SwiftWarplyFramework/SwiftWarplyFramework/CampaignViewController.swift
SwiftWarplyFramework/SwiftWarplyFramework/CampaignViewController.swift
View file @
aa2ceb5
...
...
@@ -77,6 +77,9 @@ var timer2: DispatchSourceTimer?
setBackButton
()
}
// Add observers for application state changes
NotificationCenter
.
default
.
addObserver
(
self
,
selector
:
#selector(
applicationWillEnterForeground
)
,
name
:
UIApplication
.
willEnterForegroundNotification
,
object
:
nil
)
NotificationCenter
.
default
.
addObserver
(
self
,
selector
:
#selector(
applicationDidEnterBackground
)
,
name
:
UIApplication
.
didEnterBackgroundNotification
,
object
:
nil
)
}
public
override
func
viewWillAppear
(
_
animated
:
Bool
)
{
...
...
@@ -90,14 +93,7 @@ var timer2: DispatchSourceTimer?
if
(
webViewLoaded
)
{
let
scriptSource2
=
"webviewDidFocus(
\(
self
.
webViewLoaded
)
);"
webView
.
evaluateJavaScript
(
scriptSource2
,
completionHandler
:
{
(
object
,
error
)
in
// print("==== object viewWillAppear ====")
// print(object)
// print("==== error viewWillAppear ====")
// print(error)
})
sendWebviewDidFocus
()
}
}
...
...
@@ -110,27 +106,9 @@ var timer2: DispatchSourceTimer?
stopTimer
()
let
persistedSteps
=
swiftApi
()
.
getSteps
()
if
(
persistedSteps
>
0
)
{
saveSteps
(
startTracking
:
false
)
let
currentDateTime
=
Date
()
let
dateFormatter
=
DateFormatter
()
dateFormatter
.
dateFormat
=
"yyyy-MM-dd HH:mm:ss"
let
dateString
=
dateFormatter
.
string
(
from
:
currentDateTime
)
swiftApi
()
.
setPacingDetailsAsync
(
persistedSteps
,
dateString
,
setPacingDetailsAsyncCallback
,
failureCallback
:
{
errorCode
in
})
}
func
setPacingDetailsAsyncCallback
(
_
responseData
:
swiftApi
.
GenericResponseModel
?)
->
Void
{
if
(
responseData
!=
nil
)
{
DispatchQueue
.
main
.
async
{
if
(
responseData
?
.
getStatus
==
1
)
{
// print("===== steps sent on back button press ====")
}
}
}
else
{
}
}
removeApplicationObservers
()
}
// public override func viewDidLoad() {
...
...
@@ -155,7 +133,76 @@ var timer2: DispatchSourceTimer?
// webview.configuration.userContentController.add(self, name: "Cosmote")
// }
deinit
{
// Remove observers to avoid memory leaks
removeApplicationObservers
()
}
@objc
func
applicationWillEnterForeground
()
{
// Handle code when the application is about to enter the foreground
sendWebviewDidFocus
()
}
@objc
func
applicationDidEnterBackground
()
{
// Handle code when the application enters the background
saveSteps
(
startTracking
:
false
)
}
// MARK: - Functions
func
sendWebviewDidFocus
()
{
let
scriptSource2
=
"webviewDidFocus(
\(
self
.
webViewLoaded
)
,
\(
swiftApi
()
.
getTrackingStepsEnabled
()
)
);"
webView
.
evaluateJavaScript
(
scriptSource2
,
completionHandler
:
{
(
object
,
error
)
in
// print("==== webviewDidFocus object ====")
// print(object)
// print("==== webviewDidFocus error ====")
// print(error)
})
}
func
addApplicationObservers
()
{
NotificationCenter
.
default
.
addObserver
(
self
,
selector
:
#selector(
applicationWillEnterForeground
)
,
name
:
UIApplication
.
willEnterForegroundNotification
,
object
:
nil
)
NotificationCenter
.
default
.
addObserver
(
self
,
selector
:
#selector(
applicationDidEnterBackground
)
,
name
:
UIApplication
.
didEnterBackgroundNotification
,
object
:
nil
)
}
func
removeApplicationObservers
()
{
NotificationCenter
.
default
.
removeObserver
(
self
,
name
:
UIApplication
.
willEnterForegroundNotification
,
object
:
nil
)
NotificationCenter
.
default
.
removeObserver
(
self
,
name
:
UIApplication
.
didEnterBackgroundNotification
,
object
:
nil
)
}
func
saveSteps
(
startTracking
:
Bool
)
{
let
persistedSteps
=
swiftApi
()
.
getSteps
()
if
(
persistedSteps
>
0
)
{
let
currentDateTime
=
Date
()
let
dateFormatter
=
DateFormatter
()
dateFormatter
.
dateFormat
=
"yyyy-MM-dd HH:mm:ss"
let
dateString
=
dateFormatter
.
string
(
from
:
currentDateTime
)
swiftApi
()
.
setPacingDetailsAsync
(
persistedSteps
,
dateString
,
setPacingDetailsAsyncCallback
,
failureCallback
:
{
errorCode
in
})
}
func
setPacingDetailsAsyncCallback
(
_
responseData
:
swiftApi
.
GenericResponseModel
?)
->
Void
{
if
(
responseData
!=
nil
)
{
DispatchQueue
.
main
.
async
{
if
(
responseData
?
.
getStatus
==
1
)
{
if
(
startTracking
)
{
// TODO: DELETE LOGS
// print("===== startTrackingSteps after save persisted steps ====")
self
.
sendWebviewDidFocus
()
swiftApi
()
.
startTrackingSteps
(
self
.
startTrackingStepsCallback
)
}
}
}
}
else
{
}
}
}
func
startTimer
()
{
// print("========= Webview Timer Started! =========")
...
...
@@ -172,10 +219,10 @@ var timer2: DispatchSourceTimer?
let
scriptSource
=
"passMeters(
\(
metersParam
)
);"
self
?
.
webView
.
evaluateJavaScript
(
scriptSource
,
completionHandler
:
{
(
object
,
error
)
in
//
print("==== object passMeters ====")
//
print(object)
//
print("==== error passMeters ====")
//
print(error)
//
print("==== object passMeters ====")
//
print(object)
//
print("==== error passMeters ====")
//
print(error)
swiftApi
()
.
setSavedStepsWebview
(
swiftApi
()
.
getSavedStepsWebview
()
+
swiftApi
()
.
getStepsWebview
())
swiftApi
()
.
setStepsWebview
(
0
)
...
...
@@ -340,9 +387,16 @@ var timer2: DispatchSourceTimer?
// MARK: - API Calls
func
startTrackingSteps
()
{
let
persistedSteps
=
swiftApi
()
.
getSteps
()
if
(
persistedSteps
>
0
)
{
saveSteps
(
startTracking
:
true
)
}
else
{
swiftApi
()
.
startTrackingSteps
(
startTrackingStepsCallback
)
}
// swiftApi().startTrackingSteps(startTrackingStepsCallback)
}
func
startTrackingStepsCallback
(
_
steps
:
Int
)
->
Void
{
DispatchQueue
.
main
.
async
{
}
...
...
@@ -355,9 +409,9 @@ var timer2: DispatchSourceTimer?
let
scriptSource
=
"passParams(
\(
params
)
);"
webView
.
evaluateJavaScript
(
scriptSource
,
completionHandler
:
{
(
object
,
error
)
in
// print("==== object
passParams
====")
// print("==== object ====")
// print(object)
// print("==== error
passParams
====")
// print("==== error ====")
// print(error)
DispatchQueue
.
main
.
asyncAfter
(
deadline
:
.
now
()
+
3.0
)
{
...
...
@@ -365,14 +419,14 @@ var timer2: DispatchSourceTimer?
}
})
let
scriptSource2
=
"webviewDidFocus(
\(
self
.
webViewLoaded
)
);"
webView
.
evaluateJavaScript
(
scriptSource2
,
completionHandler
:
{
(
object
,
error
)
in
// print("====
object webView
====")
// let scriptSource2 = "webviewDidFocus(\(self.webViewLoaded),\(swiftApi().getTrackingStepsEnabled()
));"
//
//
webView.evaluateJavaScript(scriptSource2, completionHandler: { (object, error) in
// print("====
webviewDidFocus object didFinish
====")
// print(object)
// print("====
error webView
====")
// print("====
webviewDidFocus error didFinish
====")
// print(error)
})
//
})
}
public
func
webView
(
_
webView
:
WKWebView
,
decidePolicyFor
navigationAction
:
WKNavigationAction
,
decisionHandler
:
@escaping
(
WKNavigationActionPolicy
)
->
Void
)
{
...
...
Please
register
or
login
to post a comment