How do I use WL.Client.getID() properly? - android

I'm trying to get the ID of a mobile phone where my hybrid worklight (v6.2) app is running on and the app is hanging on the following code:
WL.Logger.log("About to getID...");
WL.Client.getID({onSuccess : function(o) {
WL.Logger.log("getID: " + o);
devID = o.deviceID;
}, onFailure : function(e) {
WL.Logger.log("Error getting ID: " + e);
}});
WL.Logger.log("After getID...");
I see the "About to getID" output in the LogCat log, but that is it. I never see the onSuccess logging nor the onFailure logging. And the "After getID" logging never appears either.
From reading the Knowledge center documentation, it doesn't appear this method is making a call back to the Worklight server at all. This has failed both in an Android emulator and on an Android device.
Any suggestions/insight to get this method to work would be appreciated.

If you will look at the API reference for Worklight 6.2, you will see there is no such API method as WL.Client.getID: http://www-01.ibm.com/support/knowledgecenter/#!/SSZH4A_6.2.0/com.ibm.worklight.apiref.doc/html/refjavascript-client/html/WL.Client.html?cp=SSZH4A_6.2.0%2F10-0-0-1-6
There is however WL.Device.getID: http://www-01.ibm.com/support/knowledgecenter/#!/SSZH4A_6.2.0/com.ibm.worklight.apiref.doc/html/refjavascript-client/html/WL.Device.html%23getID

Related

Console log not firing in promise on android device

I'm developing an Ionic app in which I try to load the device's contacts using native plugin. There's an asynchronous call with some console logs inside but the logs are not appearing when run on android 5.1 device. The rest of the code in promise are fired, only the logs are not fired. In the browser, they appear.
public loadContactsFromDevice(): void {
console.log('ContactsProvider loadContactsFromDevice INIZIO');//this is fired
this.contacts.find(
['displayName', 'name', 'birthday'],
{ filter: "", multiple: true })
.then(resultData => {
console.log('ContactsProvider loadContactsFromDevice resultData:' + resultData);//this is not fired
this.allContacts = resultData;
this.setContactsList(this.allContacts);
});
console.log('ContactsProvider loadContactsFromDevice FINE');//this is fired
}
I found the solution. Previously I put the call to method that retrives the contacts in app.component.ts insideplatform.ready().then(){} .. When i put it outside the platform.ready() the logs are visible. I don't know why but it works.

jQuery .load() stops complete script on iPhone/Android without error message

Since I add the following lines to mij jQuery script, the whole jQuery is not working anymore on Mobile Devices. On all the PC browsers everything works fine
if ( $("input[name=campaign_id").val() ) {
$('#address').load('/Xscripts/fetch_users_data.php?cid=' + $("input[name=campaign_id").val(), function(responseTxt, statusTxt, xhr){
if(statusTxt == "error")
alert("Error by loading data: " + xhr.status + ": " + xhr.statusText);
});
};
There is no error message, but just all the jQuery functions are completely not working.
Does anyone have any clue how to fix this? How can this load code make the complete jQuery-script crashing on iPhone and Android? Removing these lines makes the rest of the script running again.
Many thanks in advance,
NiFa
OK lets try some things
1st close input attr with ] .. replace a next code in both places
$("input[name=campaign_id]").val()
------^------
2nd for load url you can try
'Xscripts/fetch_users_data.php?cid=' + $("input[name=campaign_id]").val()
or
'./Xscripts/fetch_users_data.php?cid=' + $("input[name=campaign_id]").val()
hope it helps

Phonegap- Facebook connect. Api calls doesn't fire any callback

I'm using Phonegap Build.
First of all, I need to say that this error doesn't happen if I try it with an administrator account of the app.
It only happen if a normal user tries to login in my app.
This is my code so far.
var facebookPermissions = ['public_profile', 'email', 'user_about_me', 'user_website'];
$(document).on('click', '#btnFacebook', function() { //click
facebookConnectPlugin.login(facebookPermissions, onFacebookLoginSuccess, onFacebookLoginError)
});
function onFacebookLoginSuccess(userData) {
alert("userData: " + JSON.stringify(userData));
facebookConnectPlugin.api('me', facebookPermissions,
function(result) {
alert("Result: " + JSON.stringify(result));
});
};
I'm the app's administrator and every work as expected... no trouble at all.
But if another user tries to login, the login works well, but there is no response for the api request.
Only the first alert is displayed
I also tried with this parameters
facebookConnectPlugin.api("/?fields=id,email",facebookPermissions,
facebookConnectPlugin.api("",facebookPermissions,
But nothing changes
I'm kinda lost here, and I dont know what else to try.
Your App may be in sandbox mode, activate it in the "Settings & Review" section
user_website needs to get reviewed. Without Login Review, it will only work for users with a role in the App.

Checking disk space on cordova iOS

I am trying to check disk space available in mobile using below code:
cordova.exec(function(result) {
var diskSizeInMB = result/1024;
alert(diskSizeInMB)
}, function(error) {
alert("Error: " + error);
}, "File", "getFreeDiskSpace", []);
In Android device it gives me correct result, whereas if I use iPhone/iPad it always returns me 0 as a output. Can anyone guide me how to resolve this issue? Or is there a way to check the disk size in iOS using cordova without writing custom plugin? To make this happen I haven't changed any configuration changes
It was a bug, but was fixed long time ago.
Old answer:
I confirm there is a bug on the code, the problem is getFreeDiskSpace is undocumented and cordova team want to remove the native code as getFreeDiskSpace isn't part of the w3c file API.
If you want to fix the bug for you app, go to CDVFile.m and change the line
NSNumber* pNumAvail = [self checkFreeDiskSpace:self.appDocsPath];
to
NSNumber* pNumAvail = [self checkFreeDiskSpace:self.rootDocsPath];
on the getFreeDiskSpace method

Phonegap facebook plugin for android gives me an oauthexception

seriously going insane here....
I'm trying to get the phonegap facebook plugin for android to work, but it's really driving me up the wall (no pun intented).
I am using the code from https://github.com/irnc/phonegap-plugin-facebook-connect/tree/oauth-2.0+irnc, at least I think I am.
I appear to have two problems:
the following callback in the login (from pg-plugin-fb-connect) gives an error because "FB.Auth.setAuthResponse(response.authResponse, response.status);" cannot be found. Am I using an incorrect facebook sdk? Apparently no, see edit below
PhoneGap.exec(function (response) {
console.log('PG.FB.login.success: ' + JSON.stringify(response) + ', store into localStorage ...');
localStorage.setItem(key, JSON.stringify(response));
FB.Auth.setAuthResponse(response.authResponse, response.status);
if (cb) {
cb(response);
}
}, null, service, 'login', ['publish_stream', 'read_stream']);
},
When I comment the FB.Auth.setAuthResponse(response.authResponse, response.status); statement, my login returns successfull! I get an authresponse with an accesstoken and status set to connected. When I try to execute the following code (on success callback)
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
console.log(JSON.stringify(response.error, null, 4));
alert('We are very sorry, but somthing went wrong');
} else {
alert('Message was successfully posted to your wall!');
}
});
it gives me an oauthexception message: "An active access token must be used to query information about the current user."
I authenticated with 'read_stream, publish_stream' permissions.
These two are probably related, but I can't find anything about the setAuthReponse call in the facebook api.
EDIT help is apparently not on it's way, but i've continued my quest to get this to work.
The facebook js sdk I got from the github repo's are all using the 'old' auth methods. I've downloaded the new facebook js sdk and FB.Auth.setAuthResponse is there. I copied the code to my existing js sdk and changed all calls to setSession to setAuthRepsonse. Everything is working fine, except that the access token doesn't appear to be posted when I make above FB.api calls. After these changes, the error remains exactly the same!
Oh yeah, I also changed the check in the login callback to check for authResponse instead of session (it's in the example).
Help is more than welcome,
rinze
I think I fixed this. Basically the ConnectPlugin.java is still returning a "session" response object instead of the "authResponse" that the new SDK expects.
See https://github.com/odbol/phonegap-plugin-facebook-connect/commit/0ef84e29603338930ff82fc6d6ef8525b668077d for details.

Categories

Resources