With Ionic, how can I detect when call has been disconnected? - android

The Ionic documentation for call-number is scant.
I'm trying to figure out how I can detect when a call has been disconnected. I want my app to fire a message and update a database (with call duration and other metadata) upon call completion.
Does anyone know how to do this?

Well there are two ways a phone call could end and that is handled by the onSuccess and onError parameters of the callNumber function, you can provide the handling of the call end database log via these functions.
ie.
this.callNumber.callNumber(
successres => {
// handle the success result
console.log(successres);
},
err => {
// handle errors while calling
console.log(err);
},
"18001010101",
true);

Related

React Native: Error calling JSTimers.CallTimers

I am trying to run my app on Android (One plus 6t). This was working fine before making a call to firebase but as soon as I add the line onSend={Fire.shared.send} to Chat.js, the app crashes. The logs just show Uncaught Error: Error calling JSTimers.CallTimers. Haven't seen this error anywhere else. Does anyone know what's the issue?
Here's the snack: https://snack.expo.io/#adititipnis/community
You can get this error if you omit an await call when sending JS objects to the native side, so the promise gets passed rather than the result.
I'm using the typical async sleep pattern that wraps setTimeout, so that may also be a factor in the way this error presents itself, I'm not entirely sure.
This is untested, but something like this should reproduce it:
// some async func
const asyncGetResult = async () => {
await sleep(17);
// etc.
return Promise.resolve(result);
};
// this should cause the error:
MyNativeComponent.nativeMethod({
result: asyncFunc() // <- missing 'await'
});
// this should not cause the error:
MyNativeComponent.nativeMethod({
result: await asyncFunc()
});
This can be difficult to track down if you don't know what you're looking for. I resorted to process of elimination, reverting changes file by file until I found the offending line. Hopefully this saves someone some time.

Is there a way to identify platform.resume event was called by camera?

I have an issue with my ionic v2 app, I have subscribed to platform.resume on app.component.ts where I have an redirection, based on user status, every time a picture is taken and app returns from camera platform.resume is called and the redirection breaks my app flow. Is there a way to identify resume event called by cordova-plugin-camera?
Token validation, redirects back to login page
I suggest you use Events for triggering redirection based on login/logout
events.publish('token:received', token);
and in your app.component.ts
events.subscribe('token:received',(token)=>{
//redirect
});
An internal function like platform.resume may be used internally by any number of plugins or components.
If i got it right, you can use the returned promise and then redirect to another page.
Camera.getPicture(options).then((imageData) => {
let base64Image = 'data:image/jpeg;base64,' + imageData;
this.NavCtrl.push(TheRedirectPage, ParamsYouDLikeToPass);
// i think you can also call platform.resume here, if you want, but i'd stick with the promise return.
}, (err) => {
// Handle error
});
There's no need to check with the platform.resume, since when it returns from camera it's all ready for you to do your stuff.

PouchDB replicate going to 'Pause' block on iOS 9

While developing an Ionic CouchDb-PouchDb application - I am trying to replicate the remote database as soon as the user logs in. My code looks like :
PouchDB.replicate(remote_db, local_db, {
live: true,
retry: true
}).on('change', function (info) {
// handle change
}).on('paused', function () {
// replication paused (e.g. user went offline)
}).on('active', function () {
// replicate resumed (e.g. user went back online)
}).on('denied', function (info) {
// a document failed to replicate, e.g. due to permissions
}).on('complete', function (info) {
// handle complete
}).on('error', function (err) {
// handle error
});
Each time the replicate function is invoked - it is going into the 'paused' block even if the connection was NOT interrupted.
What is going wrong?
I have used FruitDOWN adapter as suggested by Nolan Lawson in my previous question (PouchDB fails to sync on iOS 9 - iPhone 5S)
However the same code - works perfectly on Android and it enters the 'complete' block.

Android Browser not consistently return json from ajax call

I'm making an ajax call that repeatedly calls an api for json data. I've never had it fail with other browsers, but something weird is happening to the response within the Android Browser. I put a console log using weinre that catches the returned data. Can anyone make sense of it and how to handle it?
Screenshot:
Everything is running along smoothly until the last one causes an error like this: Uncaught TypeError: Cannot read property 'Requests' of undefined
Why is it not returning like the previous json return from the ajax calls?
I couldn't find anyway to handle this other than wrap the whole result in a try catch. If it does catch something then it just tries again to get the batch and has thus far always been successful on the second attempt.
try {
//ajax returned result
} catch (error) {
console.error(error);
window.setTimeout(function() {
getBatch();
}, 2000);
}

Events and callbacks firing incorrectly in pushwoosh push notifications

I'm using the plugin's registerDevice and unregisterDevice methods and looking at my app's control panel in pushwoosh. My app's preference defaults to accepting push notifications, so I register, that works and my subscriber count increments in pushwoosh control panel. It also fires a push-notification event where the event has the notification property as the guide shows, but it's set to null. This is confusing as I have not yet sent any push notifications from the control panel.
I then set my push preference to false and unregister the the device. It works because my subscriber count decrements in the control panel, but the fail callback is the one that fires, and the only argument it gets is the same push token string that the register success callback got. If I unregister again after that, still only the fail callback fires but this time the only argument is the empty string.
Am I doing something wrong with handling responses from the plugin?
The code I'm testing with:
(function() {
$document.on('push-notification', function(evt) {
var n = evt.originalEvent.notification;
console.log(n);
});
var pushPrefApply = function() {
app.pushPref(function(pushPref) {
console.log('pushPref', pushPref);
if (!pushPref) {
window.plugins.pushNotification.unregisterDevice(
function() {
console.log('unreg ok', arguments);
},
function() {
console.log('unreg fail', arguments);
}
);
return;
}
window.plugins.pushNotification.registerDevice(
{
projectid: '123456789012',
appid : 'F0000-BAAAA'
},
function(pushToken) {
console.log('reg ok', arguments);
},
function(status) {
console.log('reg fail', arguments);
}
);
});
};
//code for changing/initiating push preference goes here
})();
$document is not a typo, it's defined already. app.pushPref is the preference setting/fetching function. window.plugins.pushNotification.onDeviceReady has been done elsewhere on deviceready.
I'm hoping the pushwoosh devs will shed some light on this.
The problem has been fixed and SDK has been updated on Github:
https://github.com/shaders/push-notifications-sdk
and
https://github.com/shaders/phonegap-cordova-push-notifications
Also Android Phonegap sample now includes unregister function:
https://github.com/shaders/push-notifications-sdk/tree/master/SDK%20Sample%20Projects/Android-Phonegap

Categories

Resources