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
2022-09-07 15:55:16 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
12333de0570d3c2bcc7f2b24572130eb6f889f29
12333de0
1 parent
815c0ff1
add real time pacing data
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
0 deletions
SwiftWarplyFramework/SwiftWarplyFramework.xcworkspace/xcuserdata/manos.xcuserdatad/UserInterfaceState.xcuserstate
SwiftWarplyFramework/SwiftWarplyFramework/CampaignViewController.swift
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
SwiftWarplyFramework/SwiftWarplyFramework.xcworkspace/xcuserdata/manos.xcuserdatad/UserInterfaceState.xcuserstate
View file @
12333de
No preview for this file type
SwiftWarplyFramework/SwiftWarplyFramework/CampaignViewController.swift
View file @
12333de
...
...
@@ -10,6 +10,8 @@ import UIKit
import
WebKit
import
SwiftEventBus
var
timer
:
DispatchSourceTimer
?
@objc
public
class
CampaignViewController
:
UIViewController
,
WKNavigationDelegate
,
WKScriptMessageHandler
{
@IBOutlet
weak
var
webview
:
WKWebView
!
...
...
@@ -31,6 +33,8 @@ import SwiftEventBus
// navigationController?.setNavigationBarHidden(false, animated: animated)
self
.
navigationController
?
.
isNavigationBarHidden
=
false
}
stopTimer
()
}
public
override
func
viewDidLoad
()
{
...
...
@@ -54,6 +58,39 @@ import SwiftEventBus
webview
.
configuration
.
userContentController
.
add
(
self
,
name
:
"Cosmote"
)
}
// MARK: - Functions
func
startTimer
()
{
print
(
"========= Webview Timer Started! ========="
)
let
queue
=
DispatchQueue
(
label
:
Bundle
.
main
.
bundleIdentifier
!
+
".webview.timer"
)
timer
=
DispatchSource
.
makeTimerSource
(
queue
:
queue
)
timer
!.
schedule
(
deadline
:
.
now
(),
repeating
:
.
seconds
(
1
))
timer
!.
setEventHandler
{
[
weak
self
]
in
// do whatever stuff you want on the background queue here here
print
(
"========= Webview interval! ========="
)
DispatchQueue
.
main
.
async
{
// update your model objects and/or UI here
let
metersParam
=
swiftApi
()
.
getMetersCount
()
let
scriptSource
=
"passMeters(
\(
metersParam
)
);"
self
?
.
webview
.
evaluateJavaScript
(
scriptSource
,
completionHandler
:
{
(
object
,
error
)
in
print
(
"==== object ===="
)
print
(
object
)
print
(
"==== error ===="
)
print
(
error
)
})
}
}
timer
!.
resume
()
}
func
stopTimer
()
{
print
(
"========= Webview Timer Stopped! ========="
)
timer
?
.
cancel
()
timer
=
nil
}
// MARK: - API Calls
func
startTrackingSteps
()
{
swiftApi
()
.
startTrackingSteps
(
startTrackingStepsCallback
)
...
...
@@ -74,6 +111,8 @@ import SwiftEventBus
print
(
object
)
print
(
"==== error ===="
)
print
(
error
)
self
.
startTimer
()
})
}
...
...
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
View file @
12333de
...
...
@@ -50,6 +50,14 @@ public class swiftApi {
UserDefaults
.
standard
.
set
(
newValue
,
forKey
:
"steps"
)
}
public
func
getMetersCount
()
->
Double
{
return
UserDefaults
.
standard
.
double
(
forKey
:
"metersCount"
)
}
public
func
setMetersCount
(
_
newValue
:
Double
)
->
Void
{
UserDefaults
.
standard
.
set
(
newValue
,
forKey
:
"metersCount"
)
}
public
func
startTrackingSteps
(
_
getStepsCallback
:
@escaping
(
_
steps
:
Int
)
->
Void
)
->
Void
{
...
...
@@ -91,6 +99,16 @@ public class swiftApi {
print
((
steps
as!
Int
)
-
GlobalVariables
.
savedSteps
)
swiftApi
()
.
setSteps
((
steps
as!
Int
)
-
GlobalVariables
.
savedSteps
)
let
metersCount
=
(
steps
as?
Double
??
0.0
)
*
0.762
swiftApi
()
.
setMetersCount
(
metersCount
)
let
pacingEvent
=
swiftApi
.
HealthEventModel
()
pacingEvent
.
_meters
=
metersCount
SwiftEventBus
.
post
(
"meters_sent"
,
sender
:
pacingEvent
)
print
(
"=== MetersCount ==="
)
print
(
metersCount
)
}
getStepsCallback
(
steps
as?
Int
??
0
)
...
...
@@ -104,6 +122,9 @@ public class swiftApi {
stopTimer
()
GlobalVariables
.
savedSteps
=
0
swiftApi
()
.
setMetersCount
(
0.0
)
let
persistedSteps
=
swiftApi
()
.
getSteps
()
if
(
persistedSteps
>
0
)
{
...
...
@@ -119,6 +140,7 @@ public class swiftApi {
if
(
responseData
!=
nil
)
{
DispatchQueue
.
main
.
async
{
if
(
responseData
?
.
getStatus
==
1
)
{
GlobalVariables
.
savedSteps
=
0
}
}
}
else
{
...
...
@@ -5164,4 +5186,22 @@ public class swiftApi {
}
public
class
HealthEventModel
{
private
var
meters
:
Double
init
()
{
self
.
meters
=
0.0
}
public
var
_meters
:
Double
{
get
{
// getter
return
self
.
meters
}
set
(
newValue
)
{
//setter
self
.
meters
=
newValue
}
}
}
}
...
...
Please
register
or
login
to post a comment