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
52526e25
Commit
52526e25
authored
Dec 10, 2013
by
Chris Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Cordova runInBackground
parent
f98e253e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
19 deletions
+18
-19
CDVBackgroundGeoLocation.m
src/ios/CDVBackgroundGeoLocation.m
+18
-19
No files found.
src/ios/CDVBackgroundGeoLocation.m
View file @
52526e25
...
...
@@ -180,29 +180,17 @@
-
(
void
)
sync
{
NSLog
(
@"- CDVBackgroundGeoLocation sync"
);
// Some voodoo.
// Note that the expiration handler block simply ends the task. It is important that we always
// end tasks that we have started.
UIApplication
*
app
=
[
UIApplication
sharedApplication
];
// Inform javascript a background-fetch event has occurred.
bgTask
=
[
app
beginBackgroundTaskWithExpirationHandler
:
^
{
[
app
endBackgroundTask
:
bgTask
];
bgTask
=
UIBackgroundTaskInvalid
;
[
self
stopBackgroundTask
];
}];
// 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
];
// Fetch last recorded location
CLLocation
*
location
=
[
locationCache
lastObject
];
// Build a resultset for javascript callback.
CDVPluginResult
*
result
=
nil
;
NSMutableDictionary
*
returnInfo
=
[
NSMutableDictionary
dictionaryWithCapacity
:
8
];
NSNumber
*
timestamp
=
[
NSNumber
numberWithDouble
:([
location
.
timestamp
timeIntervalSince1970
]
*
1000
)];
[
returnInfo
setObject
:
timestamp
forKey
:
@"timestamp"
];
...
...
@@ -214,11 +202,22 @@
[
returnInfo
setObject
:[
NSNumber
numberWithDouble
:
location
.
coordinate
.
latitude
]
forKey
:
@"latitude"
];
[
returnInfo
setObject
:[
NSNumber
numberWithDouble
:
location
.
coordinate
.
longitude
]
forKey
:
@"longitude"
];
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsDictionary
:
returnInfo
];
[
result
setKeepCallbackAsBool
:
YES
];
// 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
];
// Inform javascript a background-fetch event has occurred.
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
syncCallbackId
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
syncCallbackId
];
}
];
}
-
(
void
)
onTimeExpired
:(
NSTimer
*
)
timer
{
...
...
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