Access smartphone sensors / address book from web app TODAY? - iphone

I want to give web applications running on foreign servers access to smartphone sensors and address book data. The W3C is working on a spec for that, called the Device APIs. However, it is not finished yet, and it will probably take quite some time until browser vendors provide working implementations.
But I need this functionality NOW (for a proof of concept). I do not care about portability, Android would be enough. Requiring the user to install special software first would also be OK.
Two solutions come to my mind:
Hack the APIs into the browser myself. Maybe I could take Phonegap and easily write a browser wrapper with it? That is, build a browser with Phonegap that exposes the Phonegap JS APIs to arbitrary sites (don't care about security for now)?
Write a server and run it on the smartphone localhost. This server would provide access to the resources via HTTPS and OAUTH2 (for example). Web applications could then reference this localhost server in their code (HACK HACK .. are there security mechanisms that prevent an arbitrary site from accessing a server running on localhost?).
Suggestions welcome.

Use a WebView:
http://developer.android.com/reference/android/webkit/WebView.html
This class is the basis upon which you can roll your own web browser
A WebView has several customization points where you can add your own behavior. These are:
Adding JavaScript-to-Java interfaces
with the
addJavascriptInterface(Object, String)
method. This lets you bind Java
objects into the WebView so they can
be controlled from the web pages
JavaScript.
You'd need to create an application that acts as the browser, (by implementing a custom WebView). Then in that application, create a java object for the web view that will fetch the sensor information. In the server output, write javascript that tests for and accesses this object.

For android, I believe you can expose custom local functionality to javascript either by wrapping a webview in your own lightweight "browser" application or by building a plugin for the supplied browser. As pointed out in this question How to develop plugins for the native Android browser there is an example in the sdk samples.
But I for one would be rather upset if you enabled a website to access my device's contacts, and would probably refuse to install your application on my device.

Related

Is PWA applicable for desktop web application?

I have recently gone through couple of Progressive Web application(PWA) articles on google. What I have got it it is concept for web application
which combines best of two world i.e. latest browser features(like web workers etc) and native application(speed, home page etc).
I have two basic doubts .
Is PWA applicable for mobile sites only or for desktop based application also ? In the couple of examples I have gone through mainly talks that using
PWA allows the mobile user to user the mobile sites like app without installing and equally good speed.
I understand the point with PWA user does not have to install the native app on his/her mobile but i believe even in case of PWA all content(static content like html,css,jss,images etc) will be stored in cache as user navigates to web application. Service worker checks if content
available in cache it will serve it from there otherwise fetch it from server.
So when PWA caching the content on client side, it will be equivalent
of size of native app. Is n't it ?
Its applicable to both. Think a PWA as a website that gets stored in local cache.
It really depends on what you configure service workers in the browser to do, but the gist of the thing is:
cache HTML, CSS, and JS on the client (usually on a per need basis, load and cache)
use browser local database storage to store data coming from your back end database
use AJAX, and/or WebSockets to get data back and forth from your back end systems
Call it a website, a javascript application, whatever you call it, its just the same old/new browser tricks working with local cache introduced; so it loads offline.
And loading offline is pretty much as close as they come to a native app, PWAs as of today are HTML, CSS, JS applications running on a browser; generically called a website.
Hope its clear.

PWA feature list for each browser

Where can I find list of PWA features that are supported and under development for each browser?
This will greatly help to determine if I shall develop a native app or go directly for PWA. And also know upfront what to expect in the foreseeable future in terms of browser support so that I can enhance my app with newer features.
Thanks
Actually you can try
https://whatwebcando.today/
for test your browser first
Web App Manifest, and
Service Worker API
seem to be the key technologies to watch. Google's Progressive Web App Checklist mentions both of these technologies.
However, other technologies such as BeforeInstallPromptEvent, or PWA installation notifications, are explicitly discouraged by Mozilla Developer Network, MDN:
Do not use it [BeforeInstallPromptEvent] on production sites facing the Web
Also, as an aside, commercial incentives for PWA's appear to exist:
The Supreme Court signaled Apple could face a revived antitrust
lawsuit over its price control [...and 30% take] of the iPhone and
iPad App Store. -Fortune
Google indicates that a progressive web app, PWA, is:
Progressive - Works for every user, regardless of browser choice because it's built with progressive enhancement as a core tenet.
Responsive - Fits any form factor: desktop, mobile, tablet, or whatever is next. Connectivity independent - Enhanced with service
workers to work offline or on low-quality networks.
App-like - Feels like an app, because the app shell model separates the application functionality from application content .
Fresh - Always up-to-date thanks to the service worker update process.
Safe - Served via HTTPS to prevent snooping and to ensure content hasn't been tampered with.
Discoverable - Is identifiable as an "application" thanks to W3C manifest and service worker registration scope, allowing search
engines to find it.
Re-engageable - Makes re-engagement easy through features like push notifications.
Installable - Allows users to add apps they find most useful to their home screen without the hassle of an app store.
Linkable - Easily share the application via URL, does not require complex installation.
You can check this blog about the features of PWA. Also based from this documentation, Chrome, Opera and Firefox have all implemented support for service worker with Edge having positive public signals about interest in the feature. Safari briefly mentioned interest in it via one engineer's proposed five year plan. You can also check this related thread for more information.

Database driven ios app - first steps

I'm about to start work on my first app which will be an internal release to gather customer information at a trade show.
I'm hopefully looking into using air for ios or maybe one of the various html/js frameworks to develop this app as an alternative to learning C.
ideally I would do it with some server based php > sql to store and share gathered information between a fleet of iPads, unfortunately due to the population of this trade show there will be no guarantee that i can maintain a wireless connection so need to prepare for these apps all being local access only.
in which case, how would you recommend going about the saving/reading of the stored data, and also how to sync it up with a sql server and then back to the iPads each night.
Did you try PhoneGap? It is an HTML5 app platform that allows you to author native applications with web technologies, in other words it will let you make an iphone app without having to learn C.
People have written tutorials and plugins for storing data locally.
PhoneGap basically wraps a web app hence you can use AJAX for sync with server as and when needed. This article might help.
We explored PhoneGap and found it very useful. and easy too. hope this helps you.

What are the pitfalls when implementing a web page like app?

I'm planning to implement some app that performs similar functions as some website does. An app should be able to post, get and view some data. Most viewing data is available only after login. Payments. The webservices are .NET asmx XML services.
So, I'm planning to use UIKit, drag and drop some text fiels. For posting the data, I will do some manual input validation, assemble input into a string, post it to the server. Also, some parsing will be done after getting info form a webserver. Now, I haven't done any website app before, so I'm just curious what are the potencial problems that I might run into.
I guess you are asking about potential technical issues. The ones I faced recently working on an app of this type and workarounds are:
Maintaining your session with the server if you are combining native UI screens together with UIWebView's of your website.
XML Parsing can be hairy at times, so JSON is the best option depending on your preference. The other solution is to output XML in the PLIST format which is easier to code against. On the server side PHP has some PLIST generating libraries. Am not aware of what is available on .NET.
On the iOS side the ASIHTTP library helps make it easier to post to websites, particularly when you are using binaries etc.
Depending on your use case you may also consider a pure web based UI version which resides inside a UI webview. If you are planning on going this route JQueryMobile is a pretty good solution for rendering iOS like UIs. This saves you quite a lot of effort on the communicating with the webservice and parsing etc.
Thats all I can think of for now.
Biggest problem might be getting it approved by Apple if they think it should be just a website and not an app. They might cite: "Limited Functionality". see : https://developer.apple.com/appstore/resources/approval/guidelines.html
I can also reccomend www.sudzc.com
Your UI will certainly not be as responsive as a native app.
Your users won't be able to use your app without an Internet connection/flaky connection
You'll have to rebuild all native controllers yourself if you wan't your app to look like a native iPhone app.
You'll have to rely on libraries like PhoneGap to use most of the hardware/non HTML supported functions (like geolocation, camera, etc.)
Etc.

What is good way to register users from phone app

We have a web application and we've built phone applications (iPhone, Android, BlackBerry) to be companions to the site. The usual workflow is that an existing user of the site gets a phone app and then plugs their existing credentials into the phone app and they are off and running, but more often now we are seeing folks who are downloading the app and then (and this should not surprise anyone) don't read the help screen that explains they need to go and get credentials at the web site and therefore cannot connect to the application which does require registration to manage their content. This is a giant usability fail condition.
So we know that we need to put user registration workflows on the phone app.
Other than the obvious solution of duplicating our registration page on the mobile, does anyone know of a better identity solution for the phone? For example, on the desktop we also use Facebook Connect as an identity server and the users love it. I'm looking for something that simple that we can implement across the major smartphone platforms.
Clarifying note:
I should add here that this registration mechanism is likely to; and it would be desirable if it did, go hand in hand with a general identity/authorization mechanism such as the Facebook mechanism mentioned below.
One other place I'm poking around is to see whether there's an openId solution that does not require a browser to pop up.
Restful service might be the e asiest way for you to achieve this, you can use it on any device that can make http requests, so you can make your own login screens and talk to the s ervice that way...
Facebook has a Connect API for the iPhone. Integrating it into your iPhone app is very smooth.
http://developers.facebook.com/connect_iphone.php
On the BlackBerry we were able to build a fairly robust REST pipeline between the client apps in the field and our servers. We primary use the framework for updates, but the device API is generic enough to be able to build almost anything you need via standard HTTP/HTTPS GET/POST calls.
On the RIM platform, look into the HttpConnection API as a starting point. There is also an example on the BlackBerry Developer's site which will help. Finally, I believe there are several examples inside the sample package that comes with every BlackBerry JDE (IDE + API download).