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-09 13:54:07 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b06912d53480b06dfc883dfbb848d04cb3672842
b06912d5
1 parent
93bf14c5
fix pacing already enabled
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
48 deletions
SwiftWarplyFramework/SwiftWarplyFramework/CampaignViewController.swift
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
SwiftWarplyFramework/SwiftWarplyFramework/CampaignViewController.swift
View file @
b06912d
...
...
@@ -177,7 +177,7 @@ var timer2: DispatchSourceTimer?
DispatchQueue
.
main
.
async
{
SwiftEventBus
.
post
(
"coupons_fetched"
)
print
(
"========= getCouponsRequest SUCCESSSS CampaignVC ========="
)
print
(
"========= getCouponsRequest count CampaignVC ========="
)
...
...
@@ -206,7 +206,10 @@ var timer2: DispatchSourceTimer?
let
pacingEvent
=
swiftApi
.
WarplyPacingEventModel
()
pacingEvent
.
_isVisible
=
true
SwiftEventBus
.
post
(
"pacing"
,
sender
:
pacingEvent
)
self
.
startTrackingSteps
()
if
(
swiftApi
()
.
getTrackingStepsEnabled
()
==
false
)
{
self
.
startTrackingSteps
()
}
}
else
if
(
eventArray
[
1
]
==
"steps"
&&
eventArray
[
2
]
==
"shortcutDisabled"
)
{
let
pacingEvent
=
swiftApi
.
WarplyPacingEventModel
()
...
...
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
View file @
b06912d
...
...
@@ -27,6 +27,7 @@ public struct GlobalVariables {
static
var
savedStepsWebview
:
Int
=
0
static
var
metersWebview
:
Double
=
0.0
static
var
merchantList
:
Array
<
swiftApi
.
MerchantModel
>
=
[]
static
var
trackingStepsEnabled
:
Bool
=
false
}
var
timer
:
DispatchSourceTimer
?
...
...
@@ -85,72 +86,84 @@ public class swiftApi {
GlobalVariables
.
metersWebview
=
newValue
}
public
func
getTrackingStepsEnabled
()
->
Bool
{
return
GlobalVariables
.
trackingStepsEnabled
}
public
func
setTrackingStepsEnabled
(
_
newValue
:
Bool
)
->
Void
{
GlobalVariables
.
trackingStepsEnabled
=
newValue
}
public
func
startTrackingSteps
(
_
getStepsCallback
:
@escaping
(
_
steps
:
Int
)
->
Void
)
->
Void
{
// Check if there are persistedSteps from previous app kill and save them
let
persistedSteps
=
swiftApi
()
.
getSteps
()
if
(
persistedSteps
>
0
)
{
if
(
GlobalVariables
.
trackingStepsEnabled
==
false
)
{
GlobalVariables
.
trackingStepsEnabled
=
true
let
currentDateTime
=
Date
()
let
dateFormatter
=
DateFormatter
()
dateFormatter
.
dateFormat
=
"yyyy-MM-dd HH:mm:ss"
let
dateString
=
dateFormatter
.
string
(
from
:
currentDateTime
)
// Check if there are persistedSteps from previous app kill and save them
let
persistedSteps
=
swiftApi
()
.
getSteps
()
if
(
persistedSteps
>
0
)
{
swiftApi
()
.
setPacingDetailsAsync
(
persistedSteps
,
dateString
,
setPacingDetailsAsyncCallback
)
}
func
setPacingDetailsAsyncCallback
(
_
responseData
:
swiftApi
.
GenericResponseModel
?)
->
Void
{
if
(
responseData
!=
nil
)
{
DispatchQueue
.
main
.
async
{
if
(
responseData
?
.
getStatus
==
1
)
{
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
)
}
func
setPacingDetailsAsyncCallback
(
_
responseData
:
swiftApi
.
GenericResponseModel
?)
->
Void
{
if
(
responseData
!=
nil
)
{
DispatchQueue
.
main
.
async
{
if
(
responseData
?
.
getStatus
==
1
)
{
GlobalVariables
.
savedSteps
=
0
}
}
}
else
{
}
}
else
{
}
}
let
instanceOfMyApi
=
MyApi
()
instanceOfMyApi
.
startTrackingSteps
(
startTrackingCallback
)
let
instanceOfMyApi
=
MyApi
()
instanceOfMyApi
.
startTrackingSteps
(
startTrackingCallback
)
swiftApi
()
.
startTimer
()
func
startTrackingCallback
(
_
steps
:
NSNumber
?)
->
Void
{
swiftApi
()
.
startTimer
()
print
(
"=== steps ==="
)
print
(
steps
as?
Int
??
0
)
func
startTrackingCallback
(
_
steps
:
NSNumber
?)
->
Void
{
print
(
"=== steps ==="
)
print
(
steps
as?
Int
??
0
)
if
(
steps
!=
nil
)
{
print
(
"=== steps to save ==="
)
if
(
steps
!=
nil
)
{
print
(
"=== steps to save ==="
)
print
((
steps
as!
Int
)
-
GlobalVariables
.
savedSteps
)
swiftApi
()
.
setSteps
((
steps
as!
Int
)
-
GlobalVariables
.
savedSteps
)
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
metersCount
=
(
steps
as?
Double
??
0.0
)
*
0.762
swiftApi
()
.
setMetersCount
(
metersCount
)
let
pacingEvent
=
swiftApi
.
HealthEventModel
()
pacingEvent
.
_meters
=
metersCount
SwiftEventBus
.
post
(
"meters_sent"
,
sender
:
pacingEvent
)
let
pacingEvent
=
swiftApi
.
HealthEventModel
()
pacingEvent
.
_meters
=
metersCount
SwiftEventBus
.
post
(
"meters_sent"
,
sender
:
pacingEvent
)
print
(
"=== MetersCount ==="
)
print
(
metersCount
)
print
(
"=== MetersCount ==="
)
print
(
metersCount
)
let
newStepsWebview
=
(
steps
as!
Int
)
-
GlobalVariables
.
savedStepsWebview
swiftApi
()
.
setStepsWebview
(
newStepsWebview
)
let
newMetersWebview
=
Double
(
newStepsWebview
)
*
0.762
swiftApi
()
.
setMetersWebview
(
newMetersWebview
)
let
newStepsWebview
=
(
steps
as!
Int
)
-
GlobalVariables
.
savedStepsWebview
swiftApi
()
.
setStepsWebview
(
newStepsWebview
)
let
newMetersWebview
=
Double
(
newStepsWebview
)
*
0.762
swiftApi
()
.
setMetersWebview
(
newMetersWebview
)
print
(
"=== StepsWebview ==="
)
print
(
newStepsWebview
)
print
(
"=== MetersWebview ==="
)
print
(
newMetersWebview
)
}
print
(
"=== StepsWebview ==="
)
print
(
newStepsWebview
)
print
(
"=== MetersWebview ==="
)
print
(
newMetersWebview
)
}
getStepsCallback
(
steps
as?
Int
??
0
)
getStepsCallback
(
steps
as?
Int
??
0
)
}
}
}
public
func
stopTrackingSteps
()
->
Void
{
...
...
@@ -159,6 +172,8 @@ public class swiftApi {
stopTimer
()
GlobalVariables
.
trackingStepsEnabled
=
false
GlobalVariables
.
savedSteps
=
0
swiftApi
()
.
setMetersCount
(
0.0
)
...
...
Please
register
or
login
to post a comment