我正在开发一个NativeScript应用程序,它将使用监听手机的通话状态。对于这个我使用CXCallObserver和CXCallObserverDelegate我设置如下:CXCallObserverDelegate:callChanged不触发
module.exports = {
phoneDelegate: NSObject.extend({
initWithResolveReject: function(resolve, reject){
var self = this.super.init();
if(self){
this.resolve = resolve;
this.reject = reject;
}
return self;
},
callObserverCallChanged: function(observer, call){
console.log("This log is not triggering");
if(call.hasEnded){
// call has ended
this.resolve({phoneState: "ended"});
}
if(call.isOutgoing && !call.hasConnected){
// Dialing out
this.resolve({phoneState: "outgoing call"});
}
if(!call.isOutgoing && !call.hasConnected && !call.hasEnded){
// Call is incoming
this.resolve({phoneState: "incoming call"});
}
if(call.hasConnected && !call.hasEnded){
// Call is ongoing
this.resolve({phoneState: "ongoing call"});
}
}
}, {
protocols: [CXCallObserverDelegate]
}),
registerListener: function(){
return new Promise((resolve, reject) => {
try{
this.callObserver = new CXCallObserver();
let myCallDelegate = this.phoneDelegate.alloc().initWithResolveReject(resolve, reject);
this.callObserver.setDelegateQueue(myCallDelegate, null);
console.log("phone listener registered");
} catch(error) {
reject({error: error});
}
})
}
}
侦听器得到注册,因为它应该,至少没有错误抛出,最后控制台登录“registerListener”作为执行这应该。
当我尝试拨打电话时,传入或传出都没有任何反应。至少第一个控制台登录“callObserverCallChanged”应该在任何电话状态改变时执行。但没有任何反应。
任何人有什么建议可能是错的?
我已经向NativeScript的github页面报告过这个问题,所以任何感兴趣的人都可以按照这里(https://github.com/NativeScript/NativeScript/issues/4099) –