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
d589111e
Commit
d589111e
authored
Oct 03, 2013
by
Chris Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding test feature. Combining platform js into single file
parent
697a9b57
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
130 deletions
+30
-130
CDVBackgroundGeoLocation.h
src/ios/CDVBackgroundGeoLocation.h
+1
-0
CDVBackgroundGeoLocation.m
src/ios/CDVBackgroundGeoLocation.m
+22
-10
BackgroundGeoLocation.js
www/BackgroundGeoLocation.js
+7
-0
BackgroundGeoLocation.js
www/android/BackgroundGeoLocation.js
+0
-52
BackgroundGeoLocation.js
www/ios/BackgroundGeoLocation.js
+0
-68
No files found.
src/ios/CDVBackgroundGeoLocation.h
View file @
d589111e
...
...
@@ -11,6 +11,7 @@
-
(
void
)
configure
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
start
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
stop
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
test
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
sync
;
-
(
void
)
onSuspend
:(
NSNotification
*
)
notification
;
-
(
void
)
onResume
:(
NSNotification
*
)
notification
;
...
...
src/ios/CDVBackgroundGeoLocation.m
View file @
d589111e
...
...
@@ -23,8 +23,8 @@
object:
nil
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector:
@selector
(
onResume
:)
name:
UIApplicationWillEnterForegroundNotification
selector:
@selector
(
onResume
:)
name:
UIApplicationWillEnterForegroundNotification
object:
nil
];
return
self
;
}
...
...
@@ -54,6 +54,16 @@
[
self
.
locationManager
stopMonitoringSignificantLocationChanges
];
}
-
(
void
)
test
:(
CDVInvokedUrlCommand
*
)
command
{
NSLog
(
@"CDVBackgroundGeoLocation test"
);
[
self
.
locationManager
startMonitoringSignificantLocationChanges
];
if
([
self
.
locationCache
count
]
>
0
){
[
self
sync
];
}
else
{
NSLog
(
@"CDVBackgroundGeoLocation could not find a location to sync"
);
}
}
-
(
void
)
onSuspend
:(
NSNotification
*
)
notification
{
NSLog
(
@"CDVBackgroundGeoLocation suspend"
);
...
...
@@ -63,7 +73,7 @@
[
self
.
locationManager
startMonitoringSignificantLocationChanges
];
}
}
-
(
void
)
onResume
:(
NSNotification
*
)
notification
-
(
void
)
onResume
:(
NSNotification
*
)
notification
{
NSLog
(
@"CDVBackgroundGeoLocation resume"
);
if
(
self
.
enabled
)
{
...
...
@@ -107,15 +117,15 @@
// Some voodoo.
bgTask
=
[
app
beginBackgroundTaskWithExpirationHandler
:
^
{
^
{
[
app
endBackgroundTask
:
bgTask
];
}];
}];
// Prepare a reusable Request instance. We'll reuse it each time we iterate the queue below.
NSMutableURLRequest
*
request
=
[
NSMutableURLRequest
requestWithURL
:[
NSURL
URLWithString
:
self
.
url
]
cachePolicy:
NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:
10
.
0
];
cachePolicy:
NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:
10
.
0
];
[
request
setHTTPMethod
:
@"POST"
];
[
request
setValue
:
@"application/json"
forHTTPHeaderField
:
@"Accept"
];
[
request
setValue
:
@"application/json"
forHTTPHeaderField
:
@"Content-Type"
];
...
...
@@ -125,7 +135,7 @@
// Iterate the queue.
CLLocation
*
location
;
for
(
location
in
self
.
locationCache
)
{
for
(
location
in
self
.
locationCache
)
{
// Build the json-data.
NSString
*
lat
=
[
NSString
stringWithFormat
:
@"%f"
,
location
.
coordinate
.
latitude
];
NSString
*
lng
=
[
NSString
stringWithFormat
:
@"%f"
,
location
.
coordinate
.
longitude
];
...
...
@@ -133,13 +143,15 @@
NSMutableDictionary
*
params
=
[
NSMutableDictionary
dictionary
];
NSMutableDictionary
*
data
=
[
NSMutableDictionary
dictionary
];
[
params
setValue
:
self
.
token
forKey
:
@"auth_token"
];
[
params
setValue
:
@"true"
forKey
:
@"background_geolocation"
];
[
data
setValue
:
lat
forKey
:
@"latitude"
];
[
data
setValue
:
lng
forKey
:
@"longitude"
];
[
data
setValue
:
[
location
.
timestamp
descriptionWithLocale
:[
NSLocale
systemLocale
]]
forKey
:
@"recorded_at"
];
[
params
setObject
:
data
forKey
:
@"location"
];
NSString
*
json
=
[
params
JSONString
];
NSData
*
requestData
=
[
NSData
dataWithBytes
:[
json
UTF8String
]
length
:[
json
length
]];
[
request
setHTTPBody
:
requestData
];
// Synchronous HTTP request
...
...
www/BackgroundGeoLocation.js
View file @
d589111e
...
...
@@ -47,6 +47,13 @@ module.exports = {
'
BackgroundGeoLocation
'
,
'
stop
'
,
[]);
},
test
:
function
(
success
,
failure
,
config
)
{
exec
(
success
||
function
()
{},
failure
||
function
()
{},
'
BackgroundGeoLocation
'
,
'
test
'
,
[]);
}
};
www/android/BackgroundGeoLocation.js
deleted
100644 → 0
View file @
697a9b57
/***
* Custom Cordova Background GeoLocation plugin. Uses iOS native API
* @author <chris@transistorsoft.com>
* Largely based upon http://www.mindsizzlers.com/2011/07/ios-background-location/
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
var
exec
=
require
(
"
cordova/exec
"
);
module
.
exports
=
{
configure
:
function
(
success
,
failure
,
config
)
{
if
(
!
config
.
auth_token
||
!
config
.
url
)
{
console
.
log
(
"
BackgroundGeoLocation requires an auth_token and url to report to the server
"
);
}
exec
(
success
||
function
()
{},
failure
||
function
()
{},
'
BackgroundGeoLocation
'
,
'
configure
'
,
[
config
.
auth_token
,
config
.
url
]);
},
start
:
function
(
success
,
failure
,
config
)
{
exec
(
success
||
function
()
{},
failure
||
function
()
{},
'
BackgroundGeoLocation
'
,
'
start
'
,
[]);
},
stop
:
function
(
success
,
failure
,
config
)
{
exec
(
success
||
function
()
{},
failure
||
function
()
{},
'
BackgroundGeoLocation
'
,
'
stop
'
,
[]);
}
};
www/ios/BackgroundGeoLocation.js
deleted
100644 → 0
View file @
697a9b57
/***
* Custom Cordova Background GeoLocation plugin. Uses iOS native API
* @author <chris@transistorsoft.com>
* Largely based upon http://www.mindsizzlers.com/2011/07/ios-background-location/
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
var
exec
=
require
(
'
cordova/exec
'
);
/**
* Provides access to the vibration mechanism on the device.
*/
module
.
exports
=
{
/**
* Configure the native API with our authentication-token and url to POST locations to
* TODO Native plugin assumes the json-structure as required by our rails server
* options:
* auth_token: authentication token
* url: endpoint that we post the locations to, including hostname
*/
configure
:
function
(
success
,
fail
,
options
)
{
success
=
(
typeof
(
success
)
===
'
function
'
)
?
success
:
function
()
{};
fail
=
(
typeof
(
fail
)
===
'
function
'
)
?
fail
:
function
()
{};
if
(
!
options
.
auth_token
||
!
options
.
url
)
{
var
msg
=
"
BackgroundGeoLocation requires an auth_token and url to report to the server
"
;
console
.
log
(
msg
);
fail
(
msg
);
return
;
}
return
Cordova
.
exec
(
success
,
fail
,
"
BackgroundGeoLocation
"
,
"
configure
"
,
[
options
.
auth_token
,
options
.
url
]);
},
/**
* Enable background GeoLocation
*/
start
:
function
(
success
,
fail
,
options
)
{
options
=
options
||
{};
success
=
(
typeof
(
success
)
===
'
function
'
)
?
success
:
function
()
{};
fail
=
(
typeof
(
fail
)
===
'
function
'
)
?
fail
:
function
()
{};
return
Cordova
.
exec
(
success
,
fail
,
"
BackgroundGeoLocation
"
,
"
start
"
,
[
options
]);
},
/**
* disable background GeoLocation
*/
stop
:
function
(
success
,
fail
,
options
)
{
options
=
options
||
{};
success
=
(
typeof
(
success
)
===
'
function
'
)
?
success
:
function
()
{};
fail
=
(
typeof
(
fail
)
===
'
function
'
)
?
fail
:
function
()
{};
return
Cordova
.
exec
(
success
,
fail
,
"
BackgroundGeoLocation
"
,
"
stop
"
,
[
options
]);
}
};
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