iOS make the SDK work on extension


#1

I need to track event on extension, but for now it's not possible with the actual SDK

'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.

some SDk have workaround :slight_smile:

extension UIApplication: CountlyCompatible { }
extension Countly where Base: UIApplication {
    public static var shared: UIApplication? {
        let selector = NSSelectorFromString("sharedApplication")
        guard Base.responds(to: selector) else { return nil }
        return Base.perform(selector).takeUnretainedValue() as? UIApplication
    }
}


public protocol CountlyCompatible {
    associatedtype CompatibleType
    var c: CompatibleType { get }
}

public extension CountlyCompatible {
    public var c: Countly<Self> {
        return Kingfisher(self)
    }
}

use:

    // if 'sharedApplication()' is unavailable, then return
    guard let sharedApplication = Countly<UIApplication>.shared else { return }

#2

Thanks. CC'ing @erkanyildiz for this.