Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brentonhouse/16b3b38d979a88c5e4fc31d287d0dc62 to your computer and use it in GitHub Desktop.
Save brentonhouse/16b3b38d979a88c5e4fc31d287d0dc62 to your computer and use it in GitHub Desktop.
CXCallObserver in Hyperloop and Titanium
var CallDelegate = Hyperloop.defineClass('CallDelegate', 'NSObject', ['CXCallObserverDelegate']);
CallDelegate.addMethod({
selector: 'callObserver:callChanged:',
instance: true,
arguments: [
'CXCallObserver',
'CXCall'
],
callback: function (callObserver, call) {
if (this.callChanged) {
this.callChanged(callObserver, call);
}
}
});
module.exports = CallDelegate; // Export, so it can be instantiated with "new"
var CXCallObserver = require('CallKit/CXCallObserver'); // Require native class from CallKit
var CallDelegate = require('callDelegate'); // Require delegate class from app/lib/ (Alloy) or Resources/ (Classic)
var myDelegate = new CallDelegate(); // Instantiate Delegate
myDelegate.callChanged = function (callObserver, call) {
if (call.hasConnected) {
Ti.API.info('********** voice call connected **********\n');
} else if(call.hasEnded) {
Ti.API.info('********** voice call disconnected **********/n');
}
};
var callObserver = new CXCallObserver(); // Short-form for as alloc().init()
callObserver.setDelegateQueue(myDelegate, null); // Same as "setDelegate:queue:"
// TODO: Simply wrap into a function "initializeCallObserver" and use it somewhere in your app!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment