Cordova Slack Digest

Sat, 21 Aug 2021 08:20:55 GMT

User count: 4588

Join the conversation at slack.cordova.io

Channel #general (26 messages)


Fri, 20 Aug 2021 18:12:47 GMT

@iliya.stambolov says

@norman137 can you explain how can we keep our app live in background mode and get accepted in the app store ?

Fri, 20 Aug 2021 18:14:06 GMT

@norman137 says

Not sure what you mean by “keep app live in the background”

Fri, 20 Aug 2021 18:14:48 GMT

@iliya.stambolov says

So when you go out of the app, for it to keep running

Fri, 20 Aug 2021 18:15:16 GMT

@iliya.stambolov says

There is a background mode plugin and a geolocation plugin, both not being accepted by apple..

Fri, 20 Aug 2021 18:15:18 GMT

@norman137 says

The OS reserves the right to kill the foreground of any app running in the background. When that happens the UI and thus the webview is destroyed. So running anything in the background is severely limited unless you create a plugin and do the implemented in native.

Fri, 20 Aug 2021 18:15:49 GMT

@norman137 says

oh

Fri, 20 Aug 2021 18:16:20 GMT

@norman137 says

well that usually comes down to justification. You‘re at the hands of being able to convince why it’s necessary for your app to use location in the background.

Fri, 20 Aug 2021 18:16:51 GMT

@norman137 says

Both Apple and Google have been cracking down on this as well as of lately.

Fri, 20 Aug 2021 18:17:11 GMT

@iliya.stambolov says

Because i don`t have push notifications... And am relaying on my app to make requests to the server and receive notifications...

Fri, 20 Aug 2021 18:17:31 GMT

@iliya.stambolov says

Then i am using local notifications plugin to show it to the user...

Fri, 20 Aug 2021 18:17:59 GMT

@iliya.stambolov says

But if the the user is outside the app, the requests stop...

Fri, 20 Aug 2021 18:18:03 GMT

@iliya.stambolov says

And my app sleeps

Fri, 20 Aug 2021 18:18:18 GMT

@iliya.stambolov says

Google accepted my app very fast

Fri, 20 Aug 2021 18:18:31 GMT

@norman137 says

Yes, on iOS, the webview comes completely paused while the app is in the background.

Fri, 20 Aug 2021 18:19:01 GMT

@norman137 says

Android allows the webview process to continue running in the background, but this setting is more of a hint, and not all android devices may honour the setting.

Fri, 20 Aug 2021 18:19:14 GMT

@norman137 says

By default, the setting is enabled though.

Fri, 20 Aug 2021 18:19:38 GMT

@iliya.stambolov says

There must be a way... to submit my app to the app store...

Fri, 20 Aug 2021 18:19:51 GMT

@iliya.stambolov says

Push notifications cannot be the only way..

Fri, 20 Aug 2021 18:21:28 GMT

@norman137 says

Well, Apple & Google expects you to use push notifications to notify users from a remote source (such as your server). The reasoning is because all notifications are then funnelled through a single socket on the device, rather than every app opening up their own socket or do inefficient polling strategies... So using the platform's push notification system improves battery efficiency.

Fri, 20 Aug 2021 18:22:51 GMT

@norman137 says

But if you want to do stuff in the background reliably, you can‘t really implement it in the webview. You’d have to extend the behavoiur by creating a plugin and implementing that part of the codebase in native land. Because you can't guraentee that the webview will:

A) Exist while in the background B) Have actual processing time (especially on iOS, where it is forcefully paused while in the background)

Fri, 20 Aug 2021 18:25:08 GMT

@iliya.stambolov says

You'd have to extend the behavoiur by creating a plugin and implementing that part of the codebase in native land. How to do that ?

Fri, 20 Aug 2021 18:29:00 GMT

@norman137 says

That can't really be answered here, but the docs is a good place to start reading:

https://cordova.apache.org/docs/en/10.x/guide/hybrid/plugins/index.html

I‘m not sure how to create tasks that can run in the background though. That would be platform specific. So you’ll need to also get familiar with the iOS docs and Android docs.

Fri, 20 Aug 2021 18:32:54 GMT

@norman137 says

high level, a cordova plugin consists of 2 main parts:

  1. Webview/JS land
  2. Native land for each platform the plugin supports. So you'd have JS api that the webview has access to, which provides an interface to communicate across the cordova bridge to the native environment. The native environment written in obj-c for iOS or Java for android can receive these messages and call on whatever native API necessary to do the job.

In your case you might not even need a JS implementation, but you can still have an iOS & android implementation that setups up the background task (however you do that in native, I‘m not sure... that’s something I've never done before)

Fri, 20 Aug 2021 18:34:45 GMT

@norman137 says

These links are plugin development links specific to a platform: android - https://cordova.apache.org/docs/en/10.x/guide/platforms/android/plugin.html iOS - https://cordova.apache.org/docs/en/10.x/guide/platforms/ios/plugin.html

Fri, 20 Aug 2021 18:48:35 GMT

@iliya.stambolov says

Thanks!

Fri, 20 Aug 2021 18:52:13 GMT

@norman137 says

I probably can‘t answer any questions about doing background tasks, and I’m not as much of an expert on native development, especially on the iOS side... but if you have any questions regarding the native framework, I might be able to answer them