首页 > 解决方案 > SWIFT:当拨出电话接通时振动

问题描述

当拨出电话接通时,我试图振动。但是,在委托功能中,我可以捕获此事件,但振动功能无法按预期工作。通话结束时手机震动.......

print("**************** call.hasConnected") 按预期工作。

func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {
        
        print("isOutgoing: \(call.isOutgoing ? "true, ":"false, ")" +
                "hasConnected: \(call.hasConnected ? "true, ":"false, ")" +
                "hasEnded: \(call.hasEnded ? "true, ":"false, ")" +
                "isOnHold: \(call.isOnHold ? "true":"false")\n")
        
        if call.isOutgoing && !call.hasConnected && !call.hasEnded {
            print("****************   call.isOutgoing")
            
            some codes here.
        }

        if call.isOutgoing && call.hasConnected && !call.hasEnded {
            print("****************   call.hasConnected")
            //AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
            AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
        }

        if (call.isOutgoing && call.hasConnected && call.hasEnded) {
            print("****************   call.hasEnded")
        }
    }

标签: swift

解决方案


推荐阅读