-
-
Save brentonhouse/16b3b38d979a88c5e4fc31d287d0dc62 to your computer and use it in GitHub Desktop.
CXCallObserver in Hyperloop and Titanium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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