Created
September 26, 2017 23:10
-
-
Save paulw11/0c1b8ed0773fa03c1188e6e2820acbee to your computer and use it in GitHub Desktop.
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
// | |
// PhoneCallObserver.swift | |
// | |
// Created by Paul Wilkinson on 27/9/17. | |
// Copyright © 2017 Paul Wilkinson. All rights reserved. | |
// | |
import UIKit | |
import CallKit | |
class PhoneCallObserver: NSObject { | |
static let sharedObserver = PhoneCallObserver() | |
private let serialQueue = DispatchQueue(label: "my.ios10.call.status.queue") | |
private let callObserver = CXCallObserver() | |
private override init() { | |
super.init() | |
self.callObserver.setDelegate(self, queue: self.serialQueue) | |
} | |
} | |
extension PhoneCallObserver: CXCallObserverDelegate { | |
func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) { | |
let identifier = call.uuid.uuidString | |
var state = "" | |
if call.isOutgoing { | |
state = "Outgoing " | |
} else { | |
state = "Incoming " | |
} | |
if call.isOnHold { | |
state = state+"On hold " | |
} | |
if call.hasConnected { | |
state = state+"Connected " | |
} else { | |
state = state+"Alerting " | |
} | |
if call.hasEnded { | |
state = state+"Ended" | |
} | |
print("Call \(identifier) is now in state \(state)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment