access iPhone GPS from javascript webview - javascript

I have a basic query while developing hybrid iPhone application
1) How can we access iPhone native functionalities like GPS from web UI javascript WITHOUT help of third party frameworks like quickconnect iPhone or PhoneGap
2) What is the flow , architecture for the same? i.e. how javascript communicates with the native code.
3) All comments, URL, information for the same are most welcome!
4) Can I upload my app on appstore using quickconnect?
5) I think using phonegap, we cannot upload on appstore, we have to upload on phonegap only. plz comment
Thanks

1) How can we access iPhone native functionalities like GPS from web UI javascript WITHOUT help of third party frameworks like quickconnect iPhone or PhoneGap
Check out the HTML GeoLocation API. Apple also exposes other cool stuff like accelerometer data via JavaScript APIs. So you don't always even need native code.
2) What is the flow, architecture for the same? i.e. how javascript communicates with the native code.
Actually, for some information, like location data, you do not need native code (see above). However, in general, if you want to communicate with native code from a WebView in an iPhone application, you would usually register a URL handler in the WebView's delegate, then do some fancy tricks with window.location to trigger the handler when needed. To send data back to the WebView, you just need to use the self-explanatory [webView stringByEvaluatingJavaScriptFromString:(String)] method.
For communication like this, I usually end up writing my own little library that allows me to call certain native handler methods from JavaScript and also register to receive messages from the native code. You'll probably end up doing the same. It's simple, intuitive, and fun. I recommend the experience.
3) All comments, URL, information for the same are most welcome!
See the links above.
4) Can I upload my app on appstore using quickconnect?
I've never used quickconnect so I can't answer that one.
5) I think using phonegap, we cannot upload on appstore, we have to upload on phonegap only. plz comment
I've never heard of people having trouble with posting a PhoneGap based application to the AppStore. Though I must admit I've never attempted it myself. I imagine that I would have heard if Apple had stopped accepting PhoneGap based applications. But Apple is pretty moody. So who knows?
(I'd check on my sources on that one if I were you, though)

Related

Can I use device's biometrics (face id, touch id, etc) on a ReactJS project?

For example, react-native has react-native-touch-id which allows the developer to be able to integrate the use of touch id into their react-native application, I understand that react-native makes this possible because it caters for native mobile application development but I was wondering if there was any JavaScript library, framework, plugin or a piece of code out there that I can use to achieve the same result for a web application? Obviously this will work if the web app is used on a mobile device, if not a standard password will be requested instead.
Reason for this: I already have OTP implemented for my project but I think it'd be a nice feature to enable OTP with a biometric functionality during the login process, instead of asking the user to enter their password and then provide a OTP as well.
The web app will be running on a browser and written in ReactJS, with PHP used as a server side language.
I've done extensive research on this and I've come up blank, I also don't want to use an external hardware like the CAMS fingerprint scanner.
I also understand how unlikely this is but I still think there must be some way something remotely close to this can be achieved with the rich JS ecosystem.
Any suggestion and/or idea will be very much appreciated.

Serve PyQt4 GUIs in Web-Application using HTML/CSS/JavaScript

Currently, we have a number of GUIs that have been developed using PyQt4 and PyQtGraph.
We need to make these interfaces accessible to a number of remote users and are hoping to do so by serving the GUIs through an HTML/CSS/JavaScript Web-Application.
The link below provides a few suggestions for this task, but these seem to apply to a project that is in its initial stages of creation. I'm familiar with the development of Python-JavaScript Web-Applications using the Pyramid Server and would like to use this same method for providing users access to PyQt4 GUIs that have already been developed.
https://softwareengineering.stackexchange.com/questions/109572/can-i-create-a-desktop-python-gui-application-and-run-it-as-a-web-app
So my question is, can I serve a functional PyQt4 GUI as a widget using HTML/CSS/JavaScript?
This is hard. In theory you could use a VNC-like approach that sends an image of the window to the client browser and sends user events back to the server. This will probably have poor interactivity depending on the networking and would require a lot of server power, depending on the number of users. (For an example of this, see: https://github.com/campagnola/webqt)
You're probably better off distributing the application with something like py2exe, py2app, cx_freeze, etc.
I personally haven't tried it but you could look into Wt: http://www.webtoolkit.eu/wt/
It is a C++ framework that has a Qt flavour. It has a Java version called JWt. Hence, a Jython binding exists for us Python programmers: http://www.webtoolkit.eu/wt/other_language
It is not a direct replacement of Qt, and might need modification to your Qt code to work as a Wt web app, but it certainly seems worth it to look into.

JavaScript Security Risks In Hybrid Mobile App

Let's assume HTML5 web page with (in)appropriate server-side background so that http://www.my-site.com/execute?query="SELECT * FROM Table" gets executed via AJAX and returns results. Not very smart, indeed.
But how about when in context of hybrid mobile app, i.e. HTML5 app inside iOS/Android/WindowsPhone wrapper/skeleton delivered as an application through appropriate store?
Q: Do we consider JavaScript safe when in context of hybrid mobile app?
I would say no.
If somebody looks at your network communication, or maybe if you accidently forget some debug logging, it's probably fairly easy to find out the url.
And the query probably would also work when called in a browser (being mobile or desktop).
Of course you can ask yourself: how popular is your mobile app and would anybody even try to hack it. But I wouldn't bet on that.
Edit: we usually use something like a (REST) API, and the answer from the server is JSON which is then parsed by the client. Don't let anybody be able to type in SQL queries!
A: In terms of "security" on iOS: you can browse the device with e.g. iExplorer. On Android, there are also ways (rooted device or adb). Given the phonegap structure, your javascript would then be located in the "assets_www" folder or similar. So if somebody wants to, he/she can look at the javascript source just like on the web.
It will cause a serious misery.
Once someone finds your AJAX url, they will be able to delete or insert anything into your database.
Reverse engineering of applications is very common, so one will be able to find your AJAX URL very easily once they just decompiled your app. Hybrid mobile apps can be very vulnerable if you think of them like native apps.
Additionally, using proguard will not help securing your html/js source codes, so you'd better just think of them as websites' front-end where all the sources are open, and keep the same level of security.

shouldStartLoadWithRequest delegate used for Objective-C method call

I am trying to call a Objective-C method from Javascript. I am not using any libraries such as phonegap and I have also succeeded in calling the Objective-C method but for that I am creating a iframe each time before the call then only the shouldStartLoadWithRequest delegate is invoked I just followed the below links:
UIWebView Secrets
UIWebView JavaScript to Objective-C communication
But how to make a Objective-C method call without invoking the webview delegate shouldStartLoadWithRequest?
First of all, this is a pretty big problem. I'm developing a rather large hybrid solution right now, and it's important to understand how the native part of the hybrid app works on all your target platforms before you can make your js common to all platforms.
The shouldStartLoadWithRequest method depends on using custom URLs to communicate from the webpage to the native code. Clicking on a link, say hybrid://showMenu will try to open the link in the webview, and the delegate will intercept this call in shouldStartLoadWithRequest. At that point, you will recognize the call and perform whatever actions you want, eg show a menu and tell the webview to stop the loading.
There is an equivalent function on both BlackBerry (at least before v10) and Android, and most likely Windows Phone. PhoneGap is using this technique across the platforms. All of these functions will be able to catch the hybrid://showMenu call. They all behave in a different way and you'll have to do research on your own to get the code, but I can confirm that it is absolutely possible to use the same Javascript in different native shells.
You are correct to use iframes to speed up the Javascript, but there are other tricks you'll need to do to get the best performance. They differ for each browser, so if you want the best performance your Javascript will have to differ at least a little bit across platforms. Here's a good article on how to get good performance on iOS:
iOS Hybrid App primer from CocoaControls
Now, if you still want to avoid using the URLs and webview delegate to communicate between JS and native code, you could go with the much more complicated route of using WebSockets.
For this, you would have to include a WebSocket server library in each of your native wrappers that would listen to local connections. Then your Javascript would include a WebSocket client library that it would use to pass messages to the native code. Two way communication is possible. Your JS will be more or less the same across platforms.
I haven't implemented this method myself because it's overkill for what I need, but LinkdIn's hybrid app is using it. More info here:
LinkdIn's Hybrid App diary
If you go with (2) good luck and please share your results.

Accessing Google APIs from iPhone native app

I'd like to access some Google API's from within an iPhone native app. I'm not a web programmer and have never used AJAX, but I'm guessing I need some kind of bridge between Objective-C and Javascript. Ideally I'd just fire XML at Google and process the result.
I really have no idea were to start.
Has anyone successfully done this, or know of any good resources?
See gdata-objectivec-client : the official Objective-C client library for Google Data API's (it works on the iPhone too.) See http://code.google.com/p/gdata-objectivec-client/.
Unless you mean the AJAX Search API - see http://code.google.com/apis/ajaxsearch/documentation/#fonje - that will provide a JSON response.

Categories