Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cordova-plugin-background-geolocation
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Aksimaya
cordova-plugin-background-geolocation
Commits
ca2caa40
Commit
ca2caa40
authored
Sep 07, 2014
by
Chris Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Logs. re-arrange methods
parent
de8f7ad9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
43 deletions
+37
-43
CDVBackgroundGeoLocation.m
src/ios/CDVBackgroundGeoLocation.m
+37
-43
No files found.
src/ios/CDVBackgroundGeoLocation.m
View file @
ca2caa40
...
...
@@ -144,10 +144,13 @@
-
(
void
)
flushQueue
{
NSLog
(
@"- CDVBackgroundGeoLocation#flushQueue, %lu, %d"
,
(
unsigned
long
)[
locationQueue
count
],
bgTask
==
UIBackgroundTaskInvalid
);
// Sanity-check the duration of last bgTask: If greater than 30s, kill it.
if
(
bgTask
!=
UIBackgroundTaskInvalid
)
{
if
(
-
[
lastBgTaskAt
timeIntervalSinceNow
]
>
30
.
0
)
{
NSLog
(
@"- CDVBackgroundGeoLocation#flushQueue has to kill an out-standing background-task!"
);
if
(
isDebugging
)
{
[
self
notify
:
@"Outstanding bg-task was force-killed"
];
}
[
self
stopBackgroundTask
];
}
return
;
...
...
@@ -457,19 +460,22 @@
}
}
[
self
queue
:
location
type
:
@"current"
];
// Uh-oh: already a background-task in-effect.
// If we have a bgTask hanging around for 60 seconds, kill it and move on; otherwise, wait a bit longer for the existing bgTask to finish.
/*
if (bgTask != UIBackgroundTaskInvalid) {
NSLog(@"Found existing background-task. Added to Queue");
return;
}
*/
}
/**
* Calculates distanceFilter by rounding speed to nearest 5 and multiplying by 10. Clamped at 1km max.
*/
-
(
float
)
calculateDistanceFilter
:(
float
)
speed
{
float
newDistanceFilter
=
distanceFilter
;
if
(
speed
<
100
)
{
// (rounded-speed-to-nearest-5) / 2)^2
// eg 5.2 becomes (5/2)^2
newDistanceFilter
=
pow
((
5
.
0
*
floorf
(
fabsf
(
speed
)
/
5
.
0
+
0
.
5
f
)),
2
)
+
distanceFilter
;
}
return
(
newDistanceFilter
<
1000
)
?
newDistanceFilter
:
1000
;
}
-
(
void
)
queue
:(
CLLocation
*
)
location
type
:(
id
)
type
{
NSLog
(
@"- CDVBackgroundGeoLocation queue %@"
,
type
);
...
...
@@ -478,6 +484,7 @@
[
locationQueue
addObject
:
data
];
[
self
flushQueue
];
}
-
(
UIBackgroundTaskIdentifier
)
createBackgroundTask
{
lastBgTaskAt
=
[
NSDate
date
];
...
...
@@ -486,20 +493,6 @@
}];
}
/**
* Calculates distanceFilter by rounding speed to nearest 5 and multiplying by 10. Clamped at 1km max.
*/
-
(
float
)
calculateDistanceFilter
:(
float
)
speed
{
float
newDistanceFilter
=
distanceFilter
;
if
(
speed
<
100
)
{
// (rounded-speed-to-nearest-5) / 2)^2
// eg 5.2 becomes (5/2)^2
newDistanceFilter
=
pow
((
5
.
0
*
floorf
(
fabsf
(
speed
)
/
5
.
0
+
0
.
5
f
)),
2
)
+
distanceFilter
;
}
return
(
newDistanceFilter
<
1000
)
?
newDistanceFilter
:
1000
;
}
/**
* We are running in the background if this is being executed.
* We can't assume normal network access.
...
...
@@ -534,6 +527,24 @@
}
}
-
(
void
)
fireStationaryRegionListeners
:(
NSMutableDictionary
*
)
data
{
NSLog
(
@"- CDVBackgroundGeoLocation#fireStationaryRegionListeners: %d"
,
[
locationQueue
count
]);
if
(
!
[
self
.
stationaryRegionListeners
count
])
{
[
self
stopBackgroundTask
];
return
;
}
// Any javascript stationaryRegion event-listeners?
[
data
setObject
:[
NSNumber
numberWithDouble
:
stationaryRadius
]
forKey
:
@"radius"
];
CDVPluginResult
*
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsDictionary
:
data
];
[
result
setKeepCallbackAsBool
:
YES
];
for
(
NSString
*
callbackId
in
self
.
stationaryRegionListeners
)
{
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
callbackId
];
}
}
/**
* Creates a new circle around user and region-monitors it for exit
*/
...
...
@@ -563,23 +574,6 @@
locationManager
.
desiredAccuracy
=
desiredAccuracy
;
}
-
(
void
)
fireStationaryRegionListeners
:(
NSMutableDictionary
*
)
data
{
NSLog
(
@"- CDVBackgroundGeoLocation#fireStationaryRegionListeners: %d"
,
[
locationQueue
count
]);
if
(
!
[
self
.
stationaryRegionListeners
count
])
{
[
self
stopBackgroundTask
];
return
;
}
// Any javascript stationaryRegion event-listeners?
[
data
setObject
:[
NSNumber
numberWithDouble
:
stationaryRadius
]
forKey
:
@"radius"
];
CDVPluginResult
*
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsDictionary
:
data
];
[
result
setKeepCallbackAsBool
:
YES
];
for
(
NSString
*
callbackId
in
self
.
stationaryRegionListeners
)
{
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
callbackId
];
}
}
-
(
bool
)
stationaryRegionContainsLocation
:(
CLLocation
*
)
location
{
CLCircularRegion
*
region
=
[
locationManager
.
monitoredRegions
member
:
stationaryRegion
];
return
([
region
containsCoordinate
:
location
.
coordinate
])
?
YES
:
NO
;
...
...
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