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
1253c4b9
Commit
1253c4b9
authored
Dec 12, 2013
by
Chris Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved thread-mgmt to prevent crashes
parent
52526e25
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
36 deletions
+21
-36
CDVBackgroundGeoLocation.h
src/ios/CDVBackgroundGeoLocation.h
+1
-1
CDVBackgroundGeoLocation.m
src/ios/CDVBackgroundGeoLocation.m
+20
-35
No files found.
src/ios/CDVBackgroundGeoLocation.h
View file @
1253c4b9
//
// CDVBackgroundGeoLocation.h
s
// CDVBackgroundGeoLocation.h
//
// Created by Chris Scott <chris@transistorsoft.com>
//
...
...
src/ios/CDVBackgroundGeoLocation.m
View file @
1253c4b9
...
...
@@ -170,7 +170,18 @@
// old, too close to the previous one, too inaccurate and so forth according to your own
// application design.
[
locationCache
addObjectsFromArray
:
locations
];
[
self
sync
];
UIApplication
*
app
=
[
UIApplication
sharedApplication
];
bgTask
=
[
app
beginBackgroundTaskWithExpirationHandler
:
^
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
[
self
stopBackgroundTask
];
});
}];
[
self
.
commandDelegate
runInBackground
:
^
{
[
self
sync
];
}];
}
/**
* We are running in the background if this is being executed.
...
...
@@ -179,18 +190,9 @@
*/
-
(
void
)
sync
{
NSLog
(
@"- CDVBackgroundGeoLocation sync"
);
UIApplication
*
app
=
[
UIApplication
sharedApplication
];
// Inform javascript a background-fetch event has occurred.
bgTask
=
[
app
beginBackgroundTaskWithExpirationHandler
:
^
{
[
self
stopBackgroundTask
];
}];
// Fetch last recorded location
CLLocation
*
location
=
[
locationCache
lastObject
];
NSMutableDictionary
*
returnInfo
=
[
NSMutableDictionary
dictionaryWithCapacity
:
8
];
NSNumber
*
timestamp
=
[
NSNumber
numberWithDouble
:([
location
.
timestamp
timeIntervalSince1970
]
*
1000
)];
[
returnInfo
setObject
:
timestamp
forKey
:
@"timestamp"
];
...
...
@@ -202,38 +204,21 @@
[
returnInfo
setObject
:[
NSNumber
numberWithDouble
:
location
.
coordinate
.
latitude
]
forKey
:
@"latitude"
];
[
returnInfo
setObject
:[
NSNumber
numberWithDouble
:
location
.
coordinate
.
longitude
]
forKey
:
@"longitude"
];
// Set a timer to ensure our bgTask is murdered 1s before our remaining time expires.
backgroundTimer
=
[
NSTimer
scheduledTimerWithTimeInterval
:
app
.
backgroundTimeRemaining
-
1
target:
self
selector:
@selector
(
onTimeExpired
:)
userInfo:
nil
repeats:
NO
];
[
self
.
commandDelegate
runInBackground
:
^
{
// Build a resultset for javascript callback.
CDVPluginResult
*
result
=
nil
;
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsDictionary
:
returnInfo
];
[
result
setKeepCallbackAsBool
:
YES
];
// Build a resultset for javascript callback.
CDVPluginResult
*
result
=
nil
;
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
syncCallbackId
];
}];
}
-
(
void
)
onTimeExpired
:(
NSTimer
*
)
timer
{
NSLog
(
@"- CDVBackgroundGeoLocation TIME EXPIRED"
);
[
self
stopBackgroundTask
];
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsDictionary
:
returnInfo
];
[
result
setKeepCallbackAsBool
:
YES
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
syncCallbackId
];
}
-
(
void
)
stopBackgroundTask
{
[
backgroundTimer
invalidate
];
backgroundTimer
=
nil
;
UIApplication
*
app
=
[
UIApplication
sharedApplication
];
NSLog
(
@"- CDVBackgroundGeoLocation stopBackgroundTask (remaining t: %f)"
,
app
.
backgroundTimeRemaining
);
if
(
bgTask
!=
UIBackgroundTaskInvalid
)
{
[
[
UIApplication
sharedApplication
]
endBackgroundTask
:
bgTask
];
[
app
endBackgroundTask
:
bgTask
];
bgTask
=
UIBackgroundTaskInvalid
;
}
}
...
...
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