How to handle errors using phonegap facebook connect plugin - android

I am using phonegap to develop my app on Android and iOS. So far, I have managed to implement the facebook connect plugin for Android and it works pretty well.
There is one thing I am unable to do, it is how to handle the plugin errors. For instance, when there is no network connection, the FB.login(...) does not work and I got an alert from the facebook-js-sdk.js:
line 5105 :
// CORDOVA PATCH
// If the nativeInterface arg is specified then call out to the nativeInterface
// which uses the native app rather than using the iframe / popup web
if (FB._nativeInterface) {
switch (params.method) {
case 'auth.login':
FB._nativeInterface.login(params, cb, function(e) {alert('Cordova Facebook Connect plugin fail on login!' + e);});
break;
How can I intercept that alert and display my own error? here is the code I am using for the login:
login: function(success, error) {
FB.login(function(response) {
if (response.authResponse) {
//some code ..
if (success && typeof(success) === "function") {
success();
}
} else {
alert('User cancelled login or did not fully authorize.');
if (error && typeof(error) === "function") {
error(false);
}
}
}, {scope: 'email'});
}
PS: I never enter in the else block even if I cancel the login authorization, I've got the same alert.
Am I missing something?
Thank you very much for your help.

Related

How ErrorUtils work with android for uncaught exception in React Native on debug and production mode?

I want to catch uncaught exception of android react native app. For this some blogs suggesting to use following code:
ErrorUtils.setGlobalHandler(error => {
sentry.capture(error);
NativeModules.BridgeReloader.reload()
});
But I don't know the complete mechanism to implement this. Can any one let me know how do I implement code for such requirement?
I got solution, We should use ErrorUtils handler to detect run time exception. For this we have to add
if (ErrorUtils._globalHandler) {
instance.defaultHandler = ErrorUtils.getGlobalHandler && ErrorUtils.getGlobalHandler() || ErrorUtils._globalHandler;
ErrorUtils.setGlobalHandler(this.wrapGlobalHandler); //feed errors directly to our wrapGlobalHandler function
}
and in your wrapGlobalHandler method
async wrapGlobalHandler(error, isFatal) {
//* Report error here
setTimeout (() => {
this.defaultHandler(error, isFatal); //after you're finished, call the defaultHandler so that react-native also gets the error
if (Platform.OS == 'android') {
NodeModule.reload()
}
}, 1000);
}

Meteor.call doesn’t work on android App

I created a simple app using Meteor 1.3, which has only one method. It works like that: When a button is clicked, the method is invoked - it calculates a specific value and returns the result.
The app works perfectly on the localhost server, but when I launch it on my device with "meteor run android-device", it cannot access the method (simply opens the app, but nothing happens when I press a button.
Do you know how I could resolve this?
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { ReactiveDict } from 'meteor/reactive-dict';
import './main.html';
Template.check.onCreated(function checkOnCreated() {
this.state = new ReactiveDict();
});
Template.check.events({
'click .checkit'(event, instance) {
Meteor.call('code.check', function(error, result){
if(error){
console.log('Error from the client side!');
} else {
instance.state.set('fett', result.titles[0]);
}
});
},
});
Template.check.helpers({
fett() {
const instance = Template.instance();
if (instance.state.get('fett')) {
return instance.state.get('fett');
} else {
return 'Value still not known...'
}
},
});
Ensure your smartphone's WiFi is turned on and it connected to the same WiFi network as you computer where meteor app is running. Then everything should work fine.
Also, I recommend to use chrome://inspect feature (more info here) in order to debug your app on Android. Then, you will be able quickly investigate any problems with mobile app.

Error Access Denied Reload for desktopbrowser environment in MFS 7.1

I made simple application. Added android and desktopbrowser environments. Android app works fine.
While preview desktopbrowser environment getting Error Access Denied Reload dialog box infinite times.
Made below two changes in "worklight.properties" file.
mfp.session.independent=false
mfp.attrStore.type=HttpSession
Tried with restarting server and eclipse as well.
Code to reproduce below:
function wlCommonInit(){
WL.Client.connect({
onSuccess: onConnectSuccess,
onFailure: onConnectFailure
});
}
function onConnectSuccess(){
alert("Connected to Server");
WL.Client.checkForDirectUpdate();
}
function onConnectFailure(){
alert("Connection Failure");
}
$("p").click(function(){
alert("Paragraph Clicked");
getData();
});
function loadFeedsSuccess(result){
invocationResult = result.invocationResult;
alert(JSON.stringify(invocationResult.firstName));
alert(JSON.stringify(invocationResult.lastName));
}
function loadFeedsFailure(error){
console.log("Feed retrieve failure");
alert(JSON.stringify(error));
alert("Feed retrieve failure");
}
function getData() {
var invocationData = {
adapter : 'Test',
procedure : 'getAdapter',
parameters : []
};
WL.Client.invokeProcedure(invocationData,{
onSuccess : loadFeedsSuccess,
onFailure : loadFeedsFailure,
});
}
I cannot reproduce this.
Created a new project in IBM MobileFirst Platform Studio 7.1.0.00-20160321-2138
In server\conf\worklight.properties I have set mfp.attrStore.type=HttpSession and mfp.session.independent=false
Added the Mobile Web environment
Added code for WL.Client.connect() in main.js -> wlCommonInit()
Run As -> Run on MobileFirst Development Server
Preview in Console
I got a dialog showing "success" (the success callback of onSuccess).

Cordova: (ion-google-place) google map api callback not working on Android Phone

i am using ion-google-place directive in my ionic project and when i run it in the ripple I can see that this directive works as expected, however when i deploy it on my Android phone the search bar comes up but when i type no drop down is shown.
I tried to debug the code and can see the issue to be around the following code:
var geocoder = new google.maps.Geocoder();
geocoder.geocode(req, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
scope.$apply(function () {
scope.locations = results;
});
} else {
// #TODO: Figure out what to do when the geocoding fails
console.log("error getting google place...");
}
});
the callback function is never called when running within the android phone, however from ripple its working.
Any ideas as to what I may be missing ?
EDIT 1:
I created a Blank Cordova project and added the refrences to angular and google map. Then added a button and added a ng-onclick to that button as below
$scope.onButtonClick = function () {
var api = new google.maps.places.AutocompleteService();
api.getPlacePredictions({ input: "Banga" }, function (results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
console.log("google place... success");
} else {
// #TODO: Figure out what to do when the geocoding fails
console.log("error getting google place...");
}
});
Now I see that google is not defined when debugging the Android Phone, where as same when being debugged in ripple, it is working.
is there something on the phone that can prevent the maps from being available to the app?
Regards
Kiran

Facebook apprequests dialog always returns cancelled Titanium Android?

I'm using facebook 3.0.1 titanium module. In Android, the Facebook apprequests dialog always returns as cancelled, even while the actual apprequest is send as can be seen on Facebook. Because of this I cannot store the requestid in my back-end, which makes the apprequest useless.
But in iOS it works fine.
This is my code
var fb = require('facebook');
fb.appid = 'my_app_id';
fb.permissions = ['publish_stream', 'read_stream', 'email']; // Permissions your app needs
fb.forceDialogAuth = true;
fb.addEventListener('login', function(evt) {
if (evt.success) {
fb.dialog("apprequests", {
message:"LeaugeNation",
// max_recipients : "2"
}, function(response) {
alert(JSON.stringify(response));
if(response.result) {
alert("send friend req");
// sendFacebookInvite(e.result);
}
});
} else if (evt.error) {
alert("error");
} else if (evt.cancelled) {
alert("cancelled");
} else {
alert("default");
}
});
fb.authorize();
If i run the code i'm getting the following result
{"cancelled":true,"code":-1,"success":false}
I made the following changes, but did't got the result.
changed the appid won't change result
changed the Key Hash for that Facebook App
Thanks in advance.
Can you please tell me what change, that i want to made to get the correct result in Android.
You must look to facebook setting. did you register Your activity and allow the permission from developers site which you are using here. Also If you are not exporting your app please export properly with proper keystore.

Categories

Resources