I am creating a BlackBerry app that provides the functionalities of an already existing web application but making it suitable for mobile phone users. I am creating the mobile app using PhoneGap and leveraging BlackBerry WebWorks SDK. I need to send data to and receive data (submit forms, update profiles) from the mobile app to the server where the web application runs from. I also want users of the app to chat with other users of the mobile app through the BlackBerry Internet Service (BIS). I want the mobile app to be able to query the database already created for the existing web application so existing users who have downloaded the app can view their details on their BlackBerry device instead of their computers. Can someone please recommend a solution?
With phonegap you can send XMLHttpRequests via AJAX. You can do this in pure JavaScript or even easier with jQuery.
You'll need to do the database work with a server-side language, like php.
here's a simple example, assuming you have included jQuery in your Phonegap app.
window.onload = function (){
document.addEventListener("deviceready", deviceReady, false);
}
function deviceReady{
var userName = 'Hans';
var userShoeSize = 'Medium';
$.post("http://example.com/responseHandler.php", {
userName: userName, userShoeSize:userShoeSize},
function(data) {
alert(data.greeting+data.shoeSize);
}, "json");
}
and on the server in responseHandler.php:
<?php
header("Access-Control-Allow-Origin: *");
$response = array();
$response['greeting'] = 'Hi, '.$_POST['userName'];
$response['shoeSize'] = 'Your shoes are size '.$_POST['userShoeSize'];
echo json_encode($response);
?>
By echoing out a JSON encoded string on the server, javascript can easily parse the response. You don't have to use JSON, you can work with anything echoed out on the server.
Just remember to whitelist your page and allow querystrings from other origins on your server.
Related
I am developing a mobile application using Ionic Framework for my E-commerce website developed using Woocommerce.
I need to use a single database for the users, so that the registered users can access their profiles and non-registered users can register to the website / app simultaneously with the same credentials.
I found this awesome plugin which claims to provide with REST User data to help login/register but I am unable to use this as I am already using Reactor Core and WP-API to access my products data and WordPress wouldn't allow me to use all these plugins simultaneously.
Well WordPress it self has a communication protocol which is XML-RPC you can read more on it here, However it does not have authentication method builtin.
But you can try it some thing like this:
function mynamespace_getUserID( $args ) {
global $wp_xmlrpc_server;
$wp_xmlrpc_server->escape( $args );
$blog_id = $args[0];
$username = $args[1];
$password = $args[2];
if ( ! $user = $wp_xmlrpc_server->login( $username, $password ) )
return $wp_xmlrpc_server->error;
return $user->ID;
}
function mynamespace_new_xmlrpc_methods( $methods ) {
$methods['mynamespace.getUserID'] = 'mynamespace_getUserID';
return $methods;
}
add_filter( 'xmlrpc_methods', 'mynamespace_new_xmlrpc_methods');
You can read more on Extending XML-RPC here. If you are using client side language for authentication, then you can check WordPress XmlRpc Javascript Api
I am trying to send a live stream from FMLE to a CDN, but passing through our FMS (installed locally); so the chain I have is:
FMLE => FMS => CDN
Now, publishing to the CDN is username/password protected. If I try to connect directly from FMLE to the CDN, FMLE opens a layer asking for credentials to "Connect to FMS" - I fill the form with username and password provided by the CDN, click on OK, and everithing works fine.
The problem comes when introducing the FMS: I created a simple application in FMS to republish the stream (simplified code below), and it works fine for CDN that don't ask for username/password, but I'm not able to figure out how to send credentials from the FMS application to the CDN.
Here the code I'm using (it's simplified, I'm putting here only the core code):
application.onPublish = function (oClient, oStream)
{
application.nc = new NetConnection (); // Creating new NetConnection
application.nc.connect (FMS_url); // Connecting to CDN
application.ns = new NetStream (application.nc); // Creating new NetStream
application.ns.setBufferTime (1); // Setting buffer time
application.ns.attach (oStream); // Attaching incoming streaming
application.ns.publish ("stream_name", "live"); // Publishing
}
More info:
We do need to pass through FMS, so "why don't you stream directly to the CDN ?" is not an option :-)
FMS URL and credentials are correct, it's not any typing error :-(
After application.nc.connect(), the onStatus event is fired with NetConnection.Connect.Success, but inmediately after that it is fired again with NetConnection.Connect.Closed (without any other info).
Following suggestions found on the web, I tryed things like
application.nc.connect (FMS_url);
or
application.nc.connect (FMS_url + "?username&password");
or adding
application.nc.addHeader ("Credentials", false, { userid: "username", password: "password" });
... but nothing seems to work, the result is always the same.
Any suggestion ? :-) Thank you in advance, best regards
I have a dynamic website. It uses mysql database which is provided by the hosting team. I need my android app to use the same database. How could I integrate the same.?
An Ajax request in Cordova/Phonegap is the same as using the standard jQuery:
For retrieving data I used in my app [minimalist code]:
$.getJSON(url).done(function (jsonData) {
console.debug('retrieved JSON');
// process your data here
}).fail(function () {
console.debug('cannot retrieve remote URL');
// error occurred
});
See also here: Calling a REST service from a Cordova application using jQuery and othere questions here in SO such as: How to call SOAP service from Phonegap (iPhone app).
I am experimenting with azure mobile services and have implemented the authentication example here. This works on most devices ( iOs, IE9 and chrome on desktop, IE10 Surface RT, android ) but on a WP8 device ( a Nokia 920, to be precise ) it returns
"Cannot reach window opener. It may be on a different Internet Explorer zone"
after attempting to return from the authenication providers pop-up. This is mentioned briefly in the link above, but only wrt to connecting to the service from localhost. This is not the case here and other devices work fine. It does not seem to be a problem with any particular authentication provider - all ( facebook, google, twitter, windows connect ) return the same message. And as these other devices work, it seems unlikely that the service is mis-configured, but there could very well be something subtle that I'm missing.
The way I got the authentication to work is not to use Facebook JavaScript SDK, but another flow, described here https://developers.facebook.com/docs/facebook-login/login-flow-for-web-no-jssdk/#step2
For handling the response when I get the redirect back from Facebook, I used the following code:
function handleLoginResponse() {
var frag = $.deparam.fragment();
if (frag.hasOwnProperty("access_token")) {
client.login("facebook", { access_token: frag.access_token }).then(
function () {
// do your thing when logged in
}, function (error) {
alert(error);
});
}
}
This code makes use of jQuery BBQ plugin, found here http://benalman.com/projects/jquery-bbq-plugin/.
This way I can get Facebook auth to work on WP8 and I'm able to pass the access token to Mobile Services login.
A slight problem is that now the access token sticks in my site URL, which I think is a problem if the user decides to share the URL, for example. I think I can get around this by e.g. putting the info in a cookie (or local storage) and then redirecting to the plain URL of my site.
Im building a small todo app in html5. Works fine so far but i have a problem: If the user visits http://www.mydomain.com/ he is prompted to login. If he is logged in on / a different template is served -> my main application template. Plus a cookie is set for session handling.
Now he can add/delete/edit his todos. While he is online the todos are saved on the server.
I also added a cache manifest for my site and use local storage to save his todos when he's offline. This works fine so far.
My Problem: If the user is online and logs himself out of the site, and the server isn't serving the main application template anymore, the browser uses the offline version of the site. But he should only use it if the browser is offline, not when the server is sending another template on the same path.
Someone a hint for me? Thanks in advance!
Use this function to get the cookie that is stored on your client machine. In case it returns null then that means the user is logged out. This should be done every time the page is loaded. You could also redirect the user to the login page.
var function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
var cookie = getCookie("myDomainAuthenticationCookie");
if(cookie == null)
{
window.location.href = "/myDomain.com/Accounts/Login"
}