私は、電話の通話状態を聞くことを利用するNativeScriptアプリケーションを開発しています。このために私は次のように設定CXCallObserverとCXCallObserverDelegateを使用しています:CXCallObserverDelegate:callChanged not triggering
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) –