How to put my app to run "Always On Top" using Phonegap? - javascript

I need to run my app always on top of the android system, while the user will be able to exit the app only with his own password. I was told that in order to do that i need to setup and run a Service of my own.
My question is can and how it is done using Phonegap and Jquery. How do i define and run my own service? Thanks for your help.

First, don't do that. I know that doesn't sound like an answer, but trust me, it actually is the answer. What I mean is, no, you don't want your app to be "always on top of the android system." Use the actual Android lifecycle and participate as a good citizen, don't abuse it and try to keep your app always running. I know you may have a use case that makes you think you need to do that, but you most likely don't.
Second, you can write a native service (not JS) and keep it running in the background. This is a a standard Android service. You'll need to create a PhoneGap plugin to hook into your app via the service (or you can create this yourself outside PhoneGap, either way). Then you can either do work in the background, or bring your app to the foreground via the service.
This answer may help: Creating an Android Service with Phonegap? (Have phonegap app run even when closed)
Third, again, don't do that. Most long running services are a bad idea (not all mind you, some use cases require it, a music player, etc, but most do not). It's a much better idea to create an IntentService and schedule an alarm (via AlarmManager) to launch it in the background periodically if you just need to do some occasional background work (fetch data, etc). Regardless of the use case though, a long running background service will consume a lot of resources and make users justifiably wary of your app.

I don't think Phonegap will let you create a service solely in javascript. To be able to make a service, you will have to write at least some native code. See https://stackoverflow.com/a/10427975/1721527.
I've never used Phonegap, but I think you can create a native plugin to talk to the javascript. See http://docs.phonegap.com/en/2.1.0/guide_plugin-development_index.md.html.
See Android documentation on services at http://developer.android.com/guide/components/services.html.

Related

Is there a way to run universal apps on Firebase Hosting?

I have recently deployed my Angular 2 application to Firebase hosting successfully and am really enjoying this set up so far, particularly on how easy it is to deploy using CI as well.
At the moment, I am looking at adding a universal server rendering support to my app, but I'm not sure if this is handled by Firebase Hosting, as it says it is static file only.
However, what made me think that this could be a potential feature that I am missing is that Firebase offers support for single page applications, hence I decided to ask.
If there isn't support for such apps, can we expect it in the future?
At the moment this is not possible. However since Angular 2, Google and Firebase go hand in hand I would say this it is just a matter of time.
In the meantime you can create a Node.js-based server, where you install Angular Universal, and have it connect to Firebase with the Firebase Node SDK.
Next, you simply communicate with that Node-backend from your Angular 2 application.
If you're using angularfire2, that will break universal either way. There's something in the package that calls "window" which doesn't exist on the server. Unless something changes with universal or angularfire this is a ways off
At the end of that video David East mentions that one can use Google Cloud Functions with Angular Universal and such: https://www.youtube.com/watch?v=R3v8EcYzf_M
The video itself is quite useful for firebase users. But the topic starts at approximately 23:30.
A different approach is to skip universal altogether and do something like this.
Rendertron is a headless chrome that can be launched. Similar to phantomjs. But universal gives speed.

Web scraping in react-native ios?

I am building an iOS app with react-native and looking to do some web scraping. From my understanding traditional npm packages don't work because they rely on Node.js. I know there are Objective-C/Swift libraries for web scraping but I don't understand how I would integrate those into a react-native component.
Anyone have any ideas on how to get information from a website (web scraping) in react-native?
Interesting question. Architecturally, it might be a good idea to consider building a service which can provide the scraped data via an API. The more processing power the client requires (the heavier the client-side code), the more likely you are to run into lagging / stuttering issues in the app. Phones have come a long way, but still can't match a server's power.
If you want to press ahead, I would advise using the browserified version of Cheerio.js. Basically, browserify lets you take code written for node, and use it in a browser environment. You would need to test it in JS Core on IOS, but there's a good chance everything will work.
One other option is using jQuery's load function or the fetch api included in React Native to make the call to the site (you don't have to worry about CORS), and parse the result manually.

stop and start a service with html and javascript

I have an application I support that often needs to have one of it's job services stopped then restarted in order for the end users to continue processing within the application. The vendor of the application has released a fix in newer versions of the software but my employer is not interested in upgrading for now.
for the moment, I log into the server, stop the job that is running, start it, stop the job a second time and start it a second time (it sounds weird but I promise it only works if I do it in this manner, weird flaw the vendor acknowledges.
I'd like to create a simple web html page showing the service is running and include a stop and start button to allow the end user to perform this mundane task them selves instead of having to email me to do this. I know this only takes a second but i want to know if anyone has ever built this soft or web app or know where to begin to build this.
One way (and totally insecure, and disastrous, but technically a possibility) is to use something like Flash, Java Applet or Silverlight (or any other plugin technology), they have SSH and/or VNC libraries, that can allow you to use plugins to connect to you backend, however while it's a possibility and something I did when I was young and foolish I would advice against it!
Proper way would be to have a backend, that exposes simple restful api, and will execute local commands when certain endpoints are triggered. Though again, you will have to spend some time securing it and probably shell out for SSL/TLS certificates to make sure that somebody can't sniff your Authorization details.

How do you wrap a web app as iOS app

I have this web app which works great on mobile browsers however I would like to allow this app being downloaded as "native app" through the apple app store.
My app basically consists out of three files which it serves to the client:
index.html
build.js
build.css
My research so far came to the conclusion that it is possible to do this by creating a web view with objective-c which executes the web app. Additionally you may use SDKs like phone gap to use native APIs (which is not required in this case).
Unfortunately I do not find a lot information on this by google, so I have following questions:
What is the "keyword" I am looking for (whats the term for "wrapping html app in object-c")?
Do I have to change the urls in my build.js (or can I overwrite current origin)?
Is there anything else I would need to change in build.js?
Are there any problems I should consider?
Is it possible? Yes. Will apple approve your app? Defiantly not.
From the App Store Review Guidelines:
2.12 Apps that are not very useful, are simply web sites bundled as apps,
or do not provide any lasting
entertainment value may be rejected
web shell, web app
Changing the urls for local path would work.
Depends on how build.js was written.
The above.
So what can you do?
Think how to improve your app with native code and add some functionality to it.
Focusing on the native code will help. If you'll submit an app that opens a UIWebView and that's it apple will 100% reject it.
I wrote an app for my company that wrapped a web app inside a UIWebView but had a lot of native code that would sniff the current UIWebView url and triggered functions accordingly. (Opened the cam, recorded audio, uploaded stuff to the server) so in the end it was very hybrid.
Apple rejected it with the claim that the user still sees only a webpage. I had to add a lot of other visible functionality in order for it to get approved.
Your idea seems like a very general and appealing idea for developers but as far as I know, these sort of applications are not taken very sportingly by apple app reviewer.
When I say these sort, I actually mean application which calls webpages as browser. For these type of calling browser is perfect.
Now lets talk about development. If you want to start with development then this is your takeoff place. As you have all your skills with HTML, JS and CSS, you'll rock with this development platform called Phonegap. and the beauty of this platform is you can import same build for other mobile platform as well.
Looking forward for some worthy applications. Good Luck!
Not sure, but the answers above may be out of date. The new app store guidelines do not include the quoted language about "websites bundled as apps." Perhaps Apple has eased up on this issue?
You can use a new tool called Natively It helps to wrap web apps to mobile native. They also have JS SDK to integrate with native features & pretty clear documentation.

Connect server hosted webapp to local websocket

Has anyone an idea for the following scenario?
I have a RIA-Webapplication (realized in ExtJs). What I want to implement is the possibility to use local ressources like card readers or fingerprint readers or other serial devices and filesystem access.
I thought about implementing this with a local websocket service which has to be installed by our customer before using our RIA the first time. When the webapp is loading it should scan the local machine if a websocket service is available and connect to it.
After that, local events (like new card is beeing read or recognized new finger) should be passed to the browser via websocket connection.
Any ideas how to get started with such a solution?
I have made something like that. Besides the obvious things such as read/write/poll data from the card-readers and so on, you would have to either implement everything yourself or, use a library for technology you are going to employ for your web-server. So, if you use a LAMP solution, i think there are some web-socket libraries for PHP that you can use. However, if you do everything by yourself then you have to implement everything from hand-shaking, to creating data packets. I have done everything from scratch by using .NET and it provides a number of useful libraries such as hashing. Java also would be a good option and have those kind of libraries as well. In general if you doing everything by yourself i would say the trickiest thing would be to split the data you want to transmit among various data packet. It is not that hard to do things from scratch. The RFC (https://www.rfc-editor.org/rfc/rfc6455) helped me a lot. Hopefully, this helps.

Categories

Resources