I am new to react-native and implementing simple app where app will monitor the mobile's clock time and should set some flags so as to notify user to perform some task when he starts the app.
I want to continuously monitor mobile's clock time as a background job in the react native app such that, when user opens the app and if specific time has already passed, it should set some flag to take future decision.
After some research over blogs, I found that react-native-background-task and/or background-timers can be used. But I am finding difficulty in implementing it. Can anyone help me with the implementation example for the same.
Thank you in advance.
So, from your post I'm going to assume a few things. One being you'll develop on Android as well as iOS, you just want to use a plugin (not code a module yourself).
Unfortunately, unless I'm mistaken - there's no simple answer and I'll explain.
As Android and iOS go forward they are starting to limit usage of Apps in the background, specifically Android goes into 'Doze' mode and iOS works in a similar fashion.
For Android, you'll need to consider a few things and I'll concentrate on them, as you'll need to know this before actually creating a RN app.
Doze Mode
Starting from Android 6.0 (API level 23), Android introduces two
power-saving features that extend battery life for users by managing
how apps behave when a device is not connected to a power source. Doze
reduces battery consumption by deferring background CPU and network
activity for apps when the device is unused for long periods of time.
App Standby defers background network activity for apps with which the
user has not recently interacted.
While the device is in Doze, apps' access to certain battery-intensive
resources is deferred until maintenance windows. The specific
restrictions are listed in Power Management Restrictions.
Doze and App Standby manage the behavior of all apps running on
Android 6.0 or higher, regardless whether they are specifically
targeting API level 23. To ensure the best experience for users, test
your app in Doze and App Standby modes and make any necessary
adjustments to your code. The sections below provide details.
Cruically, you'll need to note:
The system does not allow sync adapters to run.
The system does not allow JobScheduler to run.
So firstly for android, you'll (probably) need to ensure your app is in a 'whitelist'. You can check the requirements of the list here:
https://developer.android.com/training/monitoring-device-state/doze-standby
Or, you can access the maintenance window with a plugin like here:
https://github.com/transistorsoft/react-native-background-fetch
Testing
Android give you some tools to do so, mainly running:
$ adb shell dumpsys battery unplug
$ adb shell am set-inactive <packageName> true
Headless JS
You can check out headless tasks, which could suit your situation:
https://facebook.github.io/react-native/docs/headless-js-android
Caveats:
Although Android state that the operating system itself acts like documented, devices themselves can have software built in which essentially kills background processes. Nokia is one of the worst. So be aware of this.
Related
Do iOS and Android collect any sensor data (e.g. accelerometer, microphone) from smartphones?
If yes, do they have to ask for user permission like third-party apps?
Yes, of course they do - those functions would not work otherwise - it's the OS that collects the data before passing it on to apps. In iOS for example, you can turn off location services system-wide, as well as per-app.
The OS also needs to ask for permission to do so, but that's usually done on a per-app basis, and may only be temporary. Generally this is much more transparent on iOS than Android - Google's own apps get very greedy before they will work, and there is a long history of privacy abuse in Android apps.
I wrote react native application. The application is simple, more informational, it is used by Redux, Saga, several linked npm packages. The app runs in normal mode, not full-screen. The structure of the application was built on the basis of Ignite.
The problem is that on the phone (Samsung Note8) the application is recognized as a game. E.g. while app is running there is a message "The game is running" on the lock screen. Also there are additional buttons for the gamepad or something like that. In additional, app has a paddings on the top and on the bottom when it's working on real device (Samsung Note8). This effect real exists when some games running. When app is running on another device (e.g. ZTE Blade 610) it's running as usual and without any side effects.
The main version is the cause of all is Game Tools that's existed on Samsung Note8 but others apps have no similar effects and running as expected.
Is there a possibility to make a react native app as a real app but not a game? Why Game Tools recognizes my app as a game? Or what is the reason and how can it be affected?
Thanks.
I think there are few possibilities.
you (or one of your dependencies) have included the google play service API which inside of play service API has a module named games that samsung will automatically treat it as game.
You could find which of your dependency is loading google play service API and create a exclude like:
compile (project ('your.dependency')){
exclude group: 'com.google.android.gms', module:'play-services-game'
}
Your application id (can see on build.gradle) is registered on samsung game database. You could check by going into playstore and search for your application id
this is something that can happen on samsung phones due to the package name of your app.
we cant change this after the initial release, you must contact samsung developer support and they can fix it on the fly.
i wrote a gist on github about it:
https://gist.github.com/Adnan-Bacic/718eb3b4e70380696c91dc21c4804112
We use React/Redux for our web-based app in production, and it works really-really well. We've been curious about React Native, and have a few quick questions. We're looking for facts only, not opinions, and not interested in starting a debate.
In order to build our app, we would need the following:
push notifications - I see a few projects on github, but does anyone have a robust solution running in production for a real app?
background processing - what happens when this app isn't running in the foreground (does background processing run similarly as other native apps, i.e. can I go to the Apple Setting app and disable the background worker threads?
web sockets - again, I've seen a few projects on github with experimental results, and yes I've heard that "this is trivial to implement, you just have to write a poly-fill". What I want is a drop-in solution, that's well tested.
in-app purchases - has anyone connected react native to Apple's in-app purchase system.
Thanks! I realize that react-native is in early beta, but in order for us to build an app efficiently, we need to make sure these basic things are ready to go.
Push notifications are included with React Native although the API is not as mature as core APIs like the view system.
React Native actually pauses some of its work when the app is backgrounded and background processing has not been a focus yet. You would instead want to delegate work to a dispatch queue. This might work for your use case if the background processing doesn't involve application logic, which you want to keep in JS.
WebSockets work reasonably well with React Native. Several contributors have helped build up WebSocket support. Out of your four requirements, I would say that WebSockets are the best supported.
There are npm packages like react-native-in-app-utils that expose the IAP APIs.
We are developing a new Windows Store App with C# now. It is strange that the app crashed occasionally but haven't given any infomation . Now we deploy an IDE on the Surface and use it to run our code. The app crashed as the same, and the IDE didn't give any information.
So we want to know if Win8 system will kill app at some special cases ?
By the way, our all code blocks had using try-catch and we use async and await very carefully.
Most crash happend when the App access some network service.
Thank you very much!
every body!
I think there is not any systematic mechanism to make our app crash. But some bugs on the system really influence the quality of the software.
As our app, it crashed many times when using grouped GridView and when the pages enabled NavigationCachemode. After removing these features, it crashed less.
I have a small app I've made that I intend to make available on both iTunes and on Android Market (AM).
I have purchased the developer certifications for both, built my app with the Android SDK and the iOS Xcode SDK. So I think I'm most of the way along.
I'm a little fuzzy on the steps after this, though. When I launch my app, I'd like it to be available on each market on more or less the same time. I'd also like to do a little testing to try and download each app to different people's devices for a beta phase. Also, my understanding is that iTunes requires some sort of approval before it goes live (does Android require the same?).
So, what I'd like to do is be able to put my app on both AM and iTunes, but have it not be publicly available. A sort of private phase, where I can test it, have selected testers download it, make sure it is working fine, and maybe even get Apple (and Android) approval.
Then, when I'm ready to go live, then mark my apps as public.
Is there anything like that on either market? If I upload my app to either market, is it from that moment publicly available?
If there isn't any such "private" phase, what is the usual process for testing the app on different devices before making it available for sale?
The android developer site confirms that you can upload your app without publishing to allow for final testing. See more information here: Publishing on Android Market (under "Configuring options and uploading assets" header). When you actually publish the app it should be up within minutes. See this answer as well Just uploaded Android App: How long before app shows in Android Market search?
Apple has a different approval which can take hours or weeks depending on how lucky you are :) I personally have not submitted an app for approval though so I don't know if there's a way to get approval and then delay the release. I don't have a dev account with Apple so I can't log in to see their app approval guidelines apparently, but maybe this has some useful info: iOS App Store Approval Guidelines