my problem is I am working with Alamofire and I added AlamofireActivityIndicator from : AlamofireNetworkActivityIndicator GitHub
my question is how to add a view to which viewController that user is there and doing networking request , that view shows indicator instead of showing indicator in status bar !
I have a problem and I changed framework codes to :
Original code from AlamofireNetworkActivityIndicator framework :
private var activityIndicatorState: ActivityIndicatorState = .notActive {
didSet {
switch activityIndicatorState {
case .notActive:
isNetworkActivityIndicatorVisible = false
invalidateStartDelayTimer()
invalidateCompletionDelayTimer()
case .delayingStart:
scheduleStartDelayTimer()
case .active:
invalidateCompletionDelayTimer()
isNetworkActivityIndicatorVisible = true
case .delayingCompletion:
scheduleCompletionDelayTimer()
}
}
}
and I've been added two method that creates and remove a red view 50*50 center of screen , I customize it later that will show indicator
fileprivate func myIndicatorView (superView:UIView) {
let view = UIView.init()
view.tag = 2018
view.backgroundColor = .red
superView.addSubview(view)
view.frame = CGRect(x: UIScreen.main.bounds.midX-25,
y: UIScreen.main.bounds.midY-25,
width: 50,
height: 50)
}
fileprivate func removeIndicatorView (superView:UIView) {
superView.subviews.forEach{ (myView) in
if myView.tag == 2018 {
myView.removeFromSuperview()
}
}
}
, but now my question is here :
private var activityIndicatorState: ActivityIndicatorState = .notActive {
didSet {
switch activityIndicatorState {
case .notActive:
self.myIndicatorView(superView: <#T##UIView#>)
isNetworkActivityIndicatorVisible = false
invalidateStartDelayTimer()
invalidateCompletionDelayTimer()
case .delayingStart:
scheduleStartDelayTimer()
case .active:
self.removeIndicatorView(superView: <#T##UIView#>)
invalidateCompletionDelayTimer()
isNetworkActivityIndicatorVisible = true
case .delayingCompletion:
scheduleCompletionDelayTimer()
}
}
}
Question :
how to define ViewControllers view instead of <#T##UIView#> ! ?? ? this framework usage is you type one line in appDelegate and it observer for every networking request :
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
NetworkActivityIndicatorManager.shared.isEnabled = true
return true
}