I am trying to create an App that will respond with locations of people in a group when anyone requests it - similar to what Find My Friends (FMF) does but across Android and iOS and I am using Phonegap. I have been researching how the FMF App returns locations - along the lines of this SO Post and am trying to understand that better.
At some point iOS will terminate the App due to memory pressure. I understand if you set your Background mode in Capabilities section of XCode to location and if there is a significant change in location the App will restart in Background. Is that what the FMF App is doing to ensure it stays up to respond to location request?
When location is requested I send a push notification (data notification only so it is processed in the background - users doesn't see it) and the App is expected to respond if it is in Background/Foreground. However in the case of iOS if the App has been terminated by iOS and there has been no significant location change, the App will not be up and running in Background and won't respond. Is that the best we can do besides somehow preventing iOS from suspending/terminating the App? Appreciate any insights.
I have read about creating background services to help but that seems to apply more to Android than to iOS.
Thank you for any guidance and pointers.
Sanjay.
First of all, you shoud Declaring Your App’s Supported Background Tasks.
Support for some types of background execution must be declared in advance by the app that uses them. In Xcode 5 and later, you declare the background modes your app supports from the Capabilities tab of your project settings. Enabling the Background Modes option adds the UIBackgroundModes key to your app’s Info.plist file. Selecting one or more checkboxes adds the corresponding background mode values to that key.
Then Tracking the User’s Location and cached the latest location.
And handle your remote notification to upload the latest location.
When your want to get somebody's location, Server push a remote-notification to the Client with APNS, and Client handle the remote-notification with application:didReceiveRemoteNotification:fetchCompletionHandler:
Or timed to upload location with Finite-Length Tasks in the background:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
bgTask = [application beginBackgroundTaskWithName:#"MyTask" expirationHandler:^{
// Clean up any unfinished task business by marking where you
// stopped or ending the task outright.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task, preferably in chunks.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
Hope that help you ~
Related
help me in any way you can, here's an application made https://play.google.com/store/apps/details?id=com.easyglobe.doublemessage the main task is to automatically send SMS when a certain location is reached (so far I've done it just through notifications), but I've been struggling with Google for a week now, provided what they wanted and a video, and explained to them that this is the main function, and created a separate window in front of the rights.
What else do they need I don't understand I chose for my application (Device Automation) I don't understand correctly or not they have a very vague explanation of what my application refers to, I can't understand what else they need to provide so that I can use SMS or is it not real?
I want to write a android native module which work as a background service and get current location and post to server and then integrate that module with react native.
if you just want it for the location then i suggest react-native-workers
it has access to native modules (network, geolocation, storage ...) you can aslo integrate it with react-native-queue
There are a couple of example projects / demo apps you might want to check out which implement both "Foreground Services" and "Background Services" in Android to help you get location updates while the app is closed or the screen is off. The background service example will only allow you to get updates as frequent as 1 minute, while the foreground service example will allow you to get updates as fast as 1 second (or maybe faster, I haven't tested that yet) while also displaying an "Ongoing Notification" to the user.
Background Service Example: https://github.com/comoser/rn-background-location
Foreground Service Example: https://github.com/andersryanc/ReactNative-LocationSample
There are a number of Android specific code adjustments you will need to make in either case. It's not ready yet, but in the near future I plan to update my repo's readme with a detailed set of instructions for implementing the necessary changes in your project.
Is it possible in react-native to execute a background task with monitoring GPS position (without running the whole app in the background), even if the phone is locked?
I want to show some information (notification) onscreen when the phone will be in some position.
I need to declare the subject of a project in my studies, but I don't know if it's possible to implement this functionality.
It most certainly is... if you have only one given position (Or fewer than 20 positions) what you'd be best using is CoreLocation's geofencing APIs!
You can set up a region like so:
if CLLocationManager.isMonitoringAvailable(for: CLCircularRegion.self) {
// Register the region.
let region = CLCircularRegion(
center: center,
radius: maxDistance, identifier: identifier
)
region.notifyOnEntry = true
locationManager.startMonitoring(for: region)
}
(Assuming you have already requested and checked the user's location permissions)!
Your app will then get launched in the background whenever a region monitoring event occurs, so you must make sure to setup a new CLLocationManager and give it a delegate to receive the updates in your application(_application:didFinishLaunchingWithOptions) function!
You can then use the delegate callbacks to trigger a local notification.
There is a slight caveat here, that this won't work if the user has disabled background app refresh for your app!
Luck, there's already a react-native library that allows you to setup these regions: https://github.com/martijndeh/react-native-region-monitor. Unfortunately I do think it will launch your JavaScript app fully (in the background of course) when a notification comes through, but that's not too big an issue.
There may also be info on the GitHub provided for how to implement this on Android too!
HERE SDK tries to start its MapService internally when consumers call MapEngine.init(). Due to Android 8 background execution restrictions, this fails if MapEngine is to be initialized from a background Service. Is there any way to initialize MapEngine that doesn't involve the SDK starting a Service internally?
The exception log:
> java.lang.IllegalStateException: Not allowed to start service Intent { act=com.here.android.mpa.service.MapService.v3 cmp=de.newecho.app/com.here.android.mpa.service.MapService (has extras) }: app is in background uid UidRecord{6924417 u0a225 CEM idle change:cached procs:1 seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1521)
at android.app.ContextImpl.startService(ContextImpl.java:1477)
at android.content.ContextWrapper.startService(ContextWrapper.java:650)
at com.nokia.maps.MapServiceClient.a(SourceFile:77)
at com.nokia.maps.MapsEngine.a(SourceFile:622)
at com.nokia.maps.MapsEngine.a(SourceFile:364)
at com.here.android.mpa.common.MapEngine.init(SourceFile:260)
EDIT:
I have no idea why this got marked as a duplicate. My question is not about how to generally handle background work on Android 8 as in the "duplicated" question. The call to startService() happens in the HERE SDK internally, so consumers have no means to change that. The question is directed towards HERE devs to clarify whether there is a way to initialize MapEngine in a manner so that the HERE SDK doesn't start a Service internally.
Within HERE Mobile SDK it is not possible to init the map from a background thread.
It is possible to continue function like Navigation in background after map init(in foreground) is done by ensuring a) The required map data is already loaded on the device, b) a foreground service is triggered
From Documentation : https://developer.here.com/documentation/android-premium/dev_guide/topics/map-guidance.html
If you are using Turn-by-Turn Navigation Mode
for driving, you can also set HERE SDK to perform guidance (including
voice instructions and event callbacks) while the app is in the
background. However, unlike the foreground navigation scenario, HERE
SDK does not stream map data during background navigation on Android.
To properly support background navigation for these devices, HERE SDK
requires your app to preload map data (such as for the current city or
state) using the MapLoader class.
Important: Starting with Android O (8.0), if your app is running in
the background, then the location system service only computes a new
location for your app a few times each hour. To avoid this behavior,
start a foreground service by following the instructions in the
Android documentation. Important: Starting with Android P (9.0), app
that requires use of foreground service must request
android.permission.FOREGROUND_SERVICE permission from the user. For
more information, please refer to Android Pie behaviour change
documentation.
I am going to enter the Samsung 2013 app contest, and one of the requirements is that you use their Chord API http://developer.samsung.com/chord.
I plan on allowing users to send messages to all phones that have my app installed. From what I gathered from the information in the previous link, this means that I will need to have a constantly running background process for users to receive the messages when they are not looking at the app at the time.
I want to know if this is true, and if so, is this viable? I am considering using the method detailed here: Android: keeping a background service alive (preventing process death) if I go ahead with this.
I'm trying to use Samsung Chord too. I thing you don't need to do this. Samsung's API Chord already provides this control.
According Chord's API:
"If a Chord node doesn’t receive a UDP signal within a specified amount of time, it considers the “missing”
node to no longer be part of the network."
And, the only thing you have to do is:
"A node cannot receive a UDP broadcast if it is in LCD-off status. Therefore, if developers want the node to discover other nodes while the application is running, the node’s status should be set to LCD-on. To do this, use Android’s PowerManager.WakeLock."
Best regards,
Adriano