I'm using this approach for Notification extensions (Service & Content), but in general you have two approaches for APIs that are unavailable in Extensions:
Delegate
Create (or reuse) a protocol that encapsulates the functionality you need. In this case, we just need the activityIndicator flag:
public protocol ActivityIndicatorDelegate {
var isNetworkActivityIndicatorVisible : Bool { get set }
}
You can have your UIApplicationDelegate implement this protocol, as a pass-through to the UIApplication.shared member.
Then, in your framework, just use the delegate as-needed:
var activityIndicatorDelegate : ActivityIndicatorDelegate? = nil;
// Begin some network activity
self.activityIndicatorDelegate?.isNetworkActivityIndicatorVisible = true;
Function Parameter
If possible, refactor your code to accept a reference to the UIApplication or UIApplicationDelegate object, and then call whatever methods you need directly.
// NOT ALLOWED IN APP EXTENSION
public static var activeTraitCollection : UITraitCollection? {
let appDelegate = UIApplication.shared.delegate;
let window = appDelegate?.window;
return window??.traitCollection;
}
// OK FOR APP EXTENSION
public static func activeTraitCollection (for appDelegate: UIApplicationDelegate) -> UITraitCollection? {
let window = appDelegate?.window;
return window??.traitCollection;
}