mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-25 21:05:09 -04:00
ask notification when open lib
This commit is contained in:
parent
ff6626320a
commit
368bdbbfaa
@ -23,6 +23,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
Preference.activeUseHistory.append(NSDate())
|
||||
}
|
||||
|
||||
func registerNotification() {
|
||||
let settings = UIUserNotificationSettings(forTypes: [.Sound, .Alert, .Badge], categories: nil)
|
||||
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
||||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
|
||||
@ -30,8 +35,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
Network.shared
|
||||
|
||||
// Register notification
|
||||
// let settings = UIUserNotificationSettings(forTypes: [.Sound, .Alert, .Badge], categories: nil) // Here are the notification permission the app wants
|
||||
// application.registerUserNotificationSettings(settings)
|
||||
if let _ = Preference.libraryLastRefreshTime { registerNotification() }
|
||||
|
||||
// Set background refresh interval
|
||||
application.setMinimumBackgroundFetchInterval(86400)
|
||||
@ -140,6 +144,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
func applicationDidEnterBackground(application: UIApplication) {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
|
||||
if #available(iOS 10, *) {
|
||||
let notification = UILocalNotification()
|
||||
notification.alertTitle = NSLocalizedString("Book download finished", comment: "Notification: Book download finished")
|
||||
notification.alertBody = NSLocalizedString("All download tasks are finished.", comment: "Notification: Book download finished")
|
||||
notification.soundName = UILocalNotificationDefaultSoundName
|
||||
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
|
||||
}
|
||||
}
|
||||
|
||||
func applicationWillEnterForeground(application: UIApplication) {
|
||||
@ -147,7 +159,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
}
|
||||
|
||||
func application(application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: () -> Void) {
|
||||
// Network.shared.rejoinSessionWithIdentifier(identifier, completionHandler: completionHandler)
|
||||
Network.shared.rejoinSessionWithIdentifier(identifier, completionHandler: completionHandler)
|
||||
}
|
||||
|
||||
// MARK: Background Refresh
|
||||
|
@ -49,7 +49,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.859</string>
|
||||
<string>1.8.871</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.862</string>
|
||||
<string>1.8.874</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionMainStoryboard</key>
|
||||
|
@ -19,5 +19,21 @@
|
||||
landmarkType = "5">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Kiwix-iOS/AppDelegate.swift"
|
||||
timestampString = "496013317.729722"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "149"
|
||||
endingLineNumber = "149"
|
||||
landmarkName = "applicationDidEnterBackground(application:)"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
@ -16,6 +16,9 @@ class Network: NSObject, NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSe
|
||||
let context = NSManagedObjectContext.mainQueueContext
|
||||
private(set) var operations = [String: DownloadBookOperation]()
|
||||
|
||||
private var downloadedBookTitle = [String]()
|
||||
private var completionHandler: (()-> Void)?
|
||||
|
||||
private override init() {
|
||||
super.init()
|
||||
queue.delegate = self
|
||||
@ -29,6 +32,11 @@ class Network: NSObject, NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSe
|
||||
return NSURLSession(configuration: configuration, delegate: self, delegateQueue: nil)
|
||||
}()
|
||||
|
||||
func rejoinSessionWithIdentifier(identifier: String, completionHandler: ()-> Void) {
|
||||
guard identifier == session.configuration.identifier else {return}
|
||||
self.completionHandler = completionHandler
|
||||
}
|
||||
|
||||
// MARK: - OperationQueueDelegate
|
||||
|
||||
func operationQueue(queue: OperationQueue, willAddOperation operation: NSOperation) {
|
||||
@ -46,6 +54,19 @@ class Network: NSObject, NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSe
|
||||
|
||||
func operationQueue(queue: OperationQueue, willProduceOperation operation: NSOperation) {}
|
||||
|
||||
// MARK: - NSURLSessionDelegate
|
||||
|
||||
func URLSessionDidFinishEventsForBackgroundURLSession(session: NSURLSession) {
|
||||
NSOperationQueue.mainQueue().addOperationWithBlock {
|
||||
self.completionHandler?()
|
||||
|
||||
let notification = UILocalNotification()
|
||||
notification.alertTitle = NSLocalizedString("Book download finished", comment: "Notification: Book download finished")
|
||||
notification.alertBody = NSLocalizedString("All download tasks are finished.", comment: "Notification: Book download finished")
|
||||
notification.soundName = UILocalNotificationDefaultSoundName
|
||||
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
|
||||
}
|
||||
}
|
||||
// MARK: - NSURLSessionTaskDelegate
|
||||
|
||||
func URLSession(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError error: NSError?) {
|
||||
|
@ -20,6 +20,10 @@ class RefreshLibraryOperation: GroupOperation {
|
||||
process.injectResultFromDependency(retrive)
|
||||
super.init(operations: [retrive, process])
|
||||
|
||||
addObserver(WillExecuteObserver { _ in
|
||||
(UIApplication.sharedApplication().delegate as! AppDelegate).registerNotification()
|
||||
})
|
||||
|
||||
process.addObserver(DidFinishObserver { [unowned self] (operation, errors) in
|
||||
guard let operation = operation as? Process else {return}
|
||||
self.hasUpdate = operation.hasUpdate
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
//
|
||||
// ZimReader.m
|
||||
// KiwixTest
|
||||
|
Loading…
x
Reference in New Issue
Block a user