Last active
January 29, 2020 22:40
-
-
Save hansemannn/5dd6f9b98d479969c638fc2471c288c0 to your computer and use it in GitHub Desktop.
CXCallObserver in Hyperloop and Titanium
This file contains hidden or 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 hidden or 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! |
Also in my testing I saw that the event fired when call is disconnected has both hasConnected and hasEnded set to 1.
Event for call connected has hasConnected =1 and hasEnded set to 0.
So go see the correct logs; I had to reverse the order of the if
clauses.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: for this to work, add Background mode definition in
tiapp.xml