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
cfc139fb
Commit
cfc139fb
authored
Sep 01, 2014
by
Chris Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove Location-error timeout. LocationManager pausesLocationUpdatesAutomatically will work fine
parent
a3a05e74
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
22 deletions
+40
-22
CDVBackgroundGeoLocation.m
src/ios/CDVBackgroundGeoLocation.m
+40
-22
No files found.
src/ios/CDVBackgroundGeoLocation.m
View file @
cfc139fb
...
...
@@ -15,7 +15,7 @@
#define paceChangeNoSound 1112
#define acquiringLocationSound 1103
#define acquiredLocationSound 1052
#define locationError
1073
#define locationError
Sound
1073
@implementation
CDVBackgroundGeoLocation
{
BOOL
isDebugging
;
...
...
@@ -27,6 +27,8 @@
UIBackgroundTaskIdentifier
bgTask
;
NSDate
*
lastBgTaskAt
;
NSError
*
locationError
;
BOOL
isMoving
;
NSNumber
*
maxBackgroundHours
;
...
...
@@ -336,9 +338,12 @@
-
(
void
)
locationManager
:(
CLLocationManager
*
)
manager
didUpdateLocations
:(
NSArray
*
)
locations
{
NSLog
(
@"- CDVBackgroundGeoLocation didUpdateLocations (isMoving: %d)"
,
isMoving
);
locationError
=
nil
;
if
(
isMoving
&&
!
isUpdatingLocation
)
{
[
self
startUpdatingLocation
];
}
CLLocation
*
location
=
[
locations
lastObject
];
lastLocation
=
location
;
...
...
@@ -368,10 +373,6 @@
if
(
++
locationAcquisitionAttempts
==
maxStationaryLocationAttempts
)
{
isAcquiringStationaryLocation
=
NO
;
[
self
startMonitoringStationaryRegion
:
stationaryLocation
];
if
(
isDebugging
)
{
AudioServicesPlaySystemSound
(
acquiredLocationSound
);
[
self
notify
:
@"Acquired stationary location"
];
}
}
else
{
// Unacceptable stationary-location: bail-out and wait for another.
return
;
...
...
@@ -405,25 +406,38 @@
// 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
)
{
// Fail-safe: If Javascript doesn't explicitly execute our #finish method (perhaps it crashed or waiting for long HTTP timeout),
// bgTask will never get cleared. Enforces that bgTask can never last longer than 60s
NSTimeInterval
duration
=
-
[
lastBgTaskAt
timeIntervalSinceNow
];
if
(
duration
>
60
.
0
)
{
[
self
stopBackgroundTask
];
}
else
{
NSLog
(
@"Abort: found existing background-task"
);
if
(
isDebugging
)
{
[
self
notify
:
@"
found
existing background-task"
];
[
self
notify
:
@"
waiting for
existing background-task"
];
}
return
;
}
}
// Create a background-task and delegate to Javascript for syncing location
bgTask
=
[
self
createBackgroundTask
];
[
self
.
commandDelegate
runInBackground
:
^
{
[
self
sync
:
location
];
}];
NSLog
(
@" position: %f,%f, speed: %f"
,
location
.
coordinate
.
latitude
,
location
.
coordinate
.
longitude
,
location
.
speed
);
if
(
isDebugging
)
{
[
self
notify
:[
NSString
stringWithFormat
:
@"Location update: %s
\n
SPD: %0.1f | DF: %0.1f | ACY: %d"
,
((
isMoving
)
?
"MOVING"
:
"STATIONARY"
),
fabsf
(
location
.
speed
),
locationManager
.
distanceFilter
,
(
int
)
location
.
horizontalAccuracy
]];
AudioServicesPlaySystemSound
(
locationSyncSound
);
}
}
-
(
UIBackgroundTaskIdentifier
)
createBackgroundTask
{
lastBgTaskAt
=
[
NSDate
date
];
...
...
@@ -433,7 +447,7 @@
}
/**
* Calculates distanceFilter by rounding speed to nearest 5 and multiplying by 10.
* Calculates distanceFilter by rounding speed to nearest 5 and multiplying by 10.
Clamped at 1km max.
*/
-
(
float
)
calculateDistanceFilter
:(
float
)
speed
{
...
...
@@ -441,7 +455,7 @@
if
(
speed
<
100
)
{
// (rounded-speed-to-nearest-5) / 2)^2
// eg 5.2 becomes (5/2)^2
newDistanceFilter
=
pow
((
5
.
0
*
floorf
(
speed
/
5
.
0
+
0
.
5
f
)),
2
)
+
distanceFilter
;
newDistanceFilter
=
pow
((
5
.
0
*
floorf
(
fabsf
(
speed
)
/
5
.
0
+
0
.
5
f
)),
2
)
+
distanceFilter
;
}
return
(
newDistanceFilter
<
1000
)
?
newDistanceFilter
:
1000
;
}
...
...
@@ -453,16 +467,6 @@
*/
-
(
void
)
sync
:(
CLLocation
*
)
location
{
NSLog
(
@" position: %f,%f, speed: %f"
,
location
.
coordinate
.
latitude
,
location
.
coordinate
.
longitude
,
location
.
speed
);
if
(
isDebugging
)
{
[
self
notify
:[
NSString
stringWithFormat
:
@"Location update: moving? %d
\n
SPD: %d, ACY: %d, DF: %d"
,
isMoving
,
(
int
)
location
.
speed
,
(
int
)
location
.
horizontalAccuracy
,
(
int
)
locationManager
.
distanceFilter
]];
AudioServicesPlaySystemSound
(
locationSyncSound
);
}
NSMutableDictionary
*
returnInfo
=
[
NSMutableDictionary
dictionaryWithCapacity
:
8
];
NSNumber
*
timestamp
=
[
NSNumber
numberWithDouble
:([
location
.
timestamp
timeIntervalSince1970
]
*
1000
)];
[
returnInfo
setObject
:
timestamp
forKey
:
@"timestamp"
];
...
...
@@ -490,6 +494,10 @@
CLLocationCoordinate2D
coord
=
[
location
coordinate
];
NSLog
(
@"- CDVBackgroundGeoLocation createStationaryRegion (%f,%f)"
,
coord
.
latitude
,
coord
.
longitude
);
if
(
isDebugging
)
{
AudioServicesPlaySystemSound
(
acquiredLocationSound
);
[
self
notify
:
@"Acquired stationary location"
];
}
if
(
stationaryRegion
!=
nil
)
{
[
locationManager
stopMonitoringForRegion
:
stationaryRegion
];
}
...
...
@@ -539,7 +547,13 @@
if
(
isDebugging
)
{
[
self
notify
:
@"Stop detected"
];
}
[
self
setPace
:
NO
];
if
(
locationError
)
{
isMoving
=
NO
;
[
self
startMonitoringStationaryRegion
:
lastLocation
];
[
self
stopUpdatingLocation
];
}
else
{
[
self
setPace
:
NO
];
}
}
/**
...
...
@@ -560,9 +574,12 @@
{
NSLog
(
@"- CDVBackgroundGeoLocation locationManager failed: %@"
,
error
);
if
(
isDebugging
)
{
AudioServicesPlaySystemSound
(
locationError
);
AudioServicesPlaySystemSound
(
locationError
Sound
);
[
self
notify
:[
NSString
stringWithFormat
:
@"Location error: %@"
,
error
.
localizedDescription
]];
}
locationError
=
error
;
switch
(
error
.
code
)
{
case
kCLErrorLocationUnknown
:
case
kCLErrorNetwork
:
...
...
@@ -580,14 +597,15 @@
[
self
stopUpdatingLocation
];
}
}
-
(
void
)
stopUpdatingLocation
{
[
locationManager
stopUpdatingLocation
];
isUpdatingLocation
=
NO
;
}
-
(
void
)
startUpdatingLocation
{
locationManager
.
pausesLocationUpdatesAutomatically
=
YES
;
[
locationManager
startUpdatingLocation
];
isUpdatingLocation
=
YES
;
}
...
...
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