update
This commit is contained in:
96
OrderScheduling/Global/Tool/SystemCall.swift
Normal file
96
OrderScheduling/Global/Tool/SystemCall.swift
Normal file
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// SystemCall.swift
|
||||
// OrderScheduling
|
||||
//
|
||||
// Created by 中道 on 2023/9/1.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreTelephony
|
||||
import RxSwift
|
||||
import RxRelay
|
||||
|
||||
public let SC = SystemCall.default
|
||||
|
||||
open class SystemCall {
|
||||
public static let `default` = SystemCall()
|
||||
|
||||
private let callCenter : CTCallCenter
|
||||
|
||||
public var callSuccess : Bool
|
||||
|
||||
private var isDialing : Bool = false
|
||||
|
||||
private var isConnected : Bool = false
|
||||
|
||||
private var isDisconnected : Bool = false
|
||||
|
||||
private var callTime : String?
|
||||
|
||||
private var connectTimeInterval : TimeInterval?
|
||||
|
||||
private var disconnectTimeInterval : TimeInterval?
|
||||
|
||||
private var duration : Int?
|
||||
|
||||
public var userOrderId : Int?
|
||||
|
||||
public var orderCode : String?
|
||||
|
||||
public var taskOrderId : Int?
|
||||
|
||||
public var uploadRelay = ReplayRelay<Any?>.create(bufferSize: 1)
|
||||
|
||||
init() {
|
||||
callCenter = CTCallCenter()
|
||||
callSuccess = false
|
||||
}
|
||||
|
||||
func callEvent(successHandler: ((Bool,String?,Int?) -> Void)? = nil) {
|
||||
callCenter.callEventHandler = {[weak self] call in
|
||||
switch call.callState {
|
||||
case "CTCallStateDialing":
|
||||
self?.isDialing = true
|
||||
self?.callTime = TOOL.getDateString(by: "yyyy-MM-dd HH:mm:ss", date: Date())
|
||||
break
|
||||
case "CTCallStateIncoming":
|
||||
self?.isDialing = false
|
||||
break
|
||||
case "CTCallStateConnected":
|
||||
self?.isConnected = true
|
||||
self?.connectTimeInterval = Date().timeIntervalSince1970
|
||||
break
|
||||
case "CTCallStateDisconnected":
|
||||
self?.isDisconnected = true
|
||||
self?.disconnectTimeInterval = Date().timeIntervalSince1970
|
||||
|
||||
if self?.isDialing == true && self?.isConnected == true {
|
||||
self?.callSuccess = true
|
||||
if successHandler != nil {
|
||||
var duration = 0
|
||||
if let disconnectTimeInterval = self?.disconnectTimeInterval,let connectTimeInterval = self?.connectTimeInterval {
|
||||
duration = Int(disconnectTimeInterval - connectTimeInterval)
|
||||
self?.duration = duration
|
||||
}
|
||||
successHandler!(true,self?.callTime,duration)
|
||||
}
|
||||
}else{
|
||||
self?.callSuccess = false
|
||||
if successHandler != nil {
|
||||
successHandler!(false,self?.callTime,0)
|
||||
}
|
||||
}
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getParameters() -> Single<UploadCallRecordParameters> {
|
||||
return Single.create {[weak self] single in
|
||||
single(.success(UploadCallRecordParameters(userOrderId: self?.userOrderId ?? 0, orderCode: self?.orderCode ?? "", taskOrderId: self?.taskOrderId ?? 0, state: self?.callSuccess == true ? 1 : 2, callTime: self?.callTime ?? "", duration: self?.duration ?? 0)))
|
||||
return Disposables.create()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user