Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for App Extension target #290

Merged
merged 1 commit into from
Apr 21, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Sources/ImageCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -511,15 +511,17 @@ extension ImageCache {
It will be called automatically when `UIApplicationDidEnterBackgroundNotification` received.
*/
@objc public func backgroundCleanExpiredDiskCache() {

// if 'sharedApplication()' is unavailable, then return
guard let sharedApplication = UIApplication.kf_sharedApplication() else { return }

func endBackgroundTask(inout task: UIBackgroundTaskIdentifier) {
UIApplication.sharedApplication().endBackgroundTask(task)
sharedApplication.endBackgroundTask(task)
task = UIBackgroundTaskInvalid
}

var backgroundTask: UIBackgroundTaskIdentifier!

backgroundTask = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler { () -> Void in
backgroundTask = sharedApplication.beginBackgroundTaskWithExpirationHandler { () -> Void in
endBackgroundTask(&backgroundTask!)
}

Expand Down Expand Up @@ -660,3 +662,14 @@ extension Dictionary {
return Array(self).sort{ isOrderedBefore($0.1, $1.1) }.map{ $0.0 }
}
}

#if !os(OSX) && !os(watchOS)
// MARK: - For App Extensions
extension UIApplication {
public static func kf_sharedApplication() -> UIApplication? {
let selector = NSSelectorFromString("sharedApplication")
guard respondsToSelector(selector) else { return nil }
return performSelector(selector).takeRetainedValue() as? UIApplication
}
}
#endif