mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-27 05:49:25 -04:00
hand off
This commit is contained in:
parent
495de1f08d
commit
d75ec14624
@ -39,29 +39,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
|
|
||||||
switch shortcutItem.type {
|
|
||||||
case "org.kiwix.search":
|
|
||||||
mainController?.hidePresentedController(false, completion: {
|
|
||||||
self.mainController?.showSearch(animated: false)
|
|
||||||
completionHandler(true)
|
|
||||||
})
|
|
||||||
case "org.kiwix.bookmarks":
|
|
||||||
mainController?.hidePresentedController(false, completion: {
|
|
||||||
self.mainController?.hideSearch(animated: false)
|
|
||||||
self.mainController?.showBookmarkTBVC()
|
|
||||||
completionHandler(true)
|
|
||||||
})
|
|
||||||
case recentShortcutTypeString:
|
|
||||||
guard let urlString = shortcutItem.userInfo?["URL"] as? String else {completionHandler(false); return}
|
|
||||||
mainController?.load(NSURL(string: urlString))
|
|
||||||
completionHandler(true)
|
|
||||||
default:
|
|
||||||
completionHandler(false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
|
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
|
||||||
// Here we get what notification permission user currently allows
|
// Here we get what notification permission user currently allows
|
||||||
}
|
}
|
||||||
@ -78,6 +55,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
|
||||||
|
if userActivity.activityType == "org.kiwix.kiwix.article-view" {
|
||||||
|
guard let navController = window?.rootViewController as? UINavigationController,
|
||||||
|
let controller = navController.topViewController as? MainController else {return false}
|
||||||
|
controller.restoreUserActivityState(userActivity)
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Active
|
// MARK: - Active
|
||||||
|
|
||||||
func applicationDidBecomeActive(application: UIApplication) {
|
func applicationDidBecomeActive(application: UIApplication) {
|
||||||
@ -103,7 +92,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
// //UIApplication.sharedApplication().applicationIconBadgeNumber = downloader.taskCount ?? 0
|
// //UIApplication.sharedApplication().applicationIconBadgeNumber = downloader.taskCount ?? 0
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// MARK: - Shotcut Items
|
// MARK: - Shotcut Items
|
||||||
|
|
||||||
|
func addRecentArticleShortCutItem(article: Article) {
|
||||||
|
guard let title = article.title else {return}
|
||||||
|
let icon = UIApplicationShortcutIcon(templateImageName: "Recent")
|
||||||
|
let item = UIMutableApplicationShortcutItem(type: recentShortcutTypeString, localizedTitle: title, localizedSubtitle: "", icon: icon, userInfo: ["URL": article.url])
|
||||||
|
UIApplication.sharedApplication().shortcutItems?.append(item)
|
||||||
|
}
|
||||||
|
|
||||||
func removeAllDynamicShortcutItems() {
|
func removeAllDynamicShortcutItems() {
|
||||||
guard let items = UIApplication.sharedApplication().shortcutItems?.filter({$0.type == recentShortcutTypeString}) else {return}
|
guard let items = UIApplication.sharedApplication().shortcutItems?.filter({$0.type == recentShortcutTypeString}) else {return}
|
||||||
@ -113,11 +109,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addRecentArticleShortCutItem(article: Article) {
|
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
|
||||||
guard let title = article.title, let url = NSURL(string: article.url) else {return}
|
switch shortcutItem.type {
|
||||||
let icon = UIApplicationShortcutIcon(templateImageName: "Recent")
|
case "org.kiwix.search":
|
||||||
let item = UIMutableApplicationShortcutItem(type: recentShortcutTypeString, localizedTitle: title, localizedSubtitle: "", icon: icon, userInfo: ["URL": url])
|
mainController?.hidePresentedController(false, completion: {
|
||||||
UIApplication.sharedApplication().shortcutItems?.append(item)
|
self.mainController?.showSearch(animated: false)
|
||||||
|
completionHandler(true)
|
||||||
|
})
|
||||||
|
case "org.kiwix.bookmarks":
|
||||||
|
mainController?.hidePresentedController(false, completion: {
|
||||||
|
self.mainController?.hideSearch(animated: false)
|
||||||
|
self.mainController?.showBookmarkTBVC()
|
||||||
|
completionHandler(true)
|
||||||
|
})
|
||||||
|
case recentShortcutTypeString:
|
||||||
|
guard let urlString = shortcutItem.userInfo?["URL"] as? String else {completionHandler(false); return}
|
||||||
|
mainController?.load(NSURL(string: urlString))
|
||||||
|
completionHandler(true)
|
||||||
|
default:
|
||||||
|
completionHandler(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Background
|
// MARK: - Background
|
||||||
|
@ -24,6 +24,7 @@ class MainController: UIViewController {
|
|||||||
|
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
|
|
||||||
|
let activityType = "org.kiwix.kiwix.article-view"
|
||||||
private var webViewInitialURL: NSURL?
|
private var webViewInitialURL: NSURL?
|
||||||
private(set) var context: UnsafeMutablePointer<Void> = nil
|
private(set) var context: UnsafeMutablePointer<Void> = nil
|
||||||
var isShowingTableOfContents = false
|
var isShowingTableOfContents = false
|
||||||
@ -38,6 +39,7 @@ class MainController: UIViewController {
|
|||||||
didSet {
|
didSet {
|
||||||
configureSearchBarPlaceHolder()
|
configureSearchBarPlaceHolder()
|
||||||
configureBookmarkButton()
|
configureBookmarkButton()
|
||||||
|
configureUserActivity()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +97,21 @@ class MainController: UIViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func updateUserActivityState(activity: NSUserActivity) {
|
||||||
|
defer { super.updateUserActivityState(activity) }
|
||||||
|
guard let article = article else {return}
|
||||||
|
activity.title = article.title
|
||||||
|
activity.addUserInfoEntriesFromDictionary(["ArticleURL": article.url])
|
||||||
|
super.updateUserActivityState(activity)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func restoreUserActivityState(activity: NSUserActivity) {
|
||||||
|
guard activity.activityType == activityType,
|
||||||
|
let urlString = activity.userInfo?["ArticleURL"] as? String,
|
||||||
|
let url = NSURL(string: urlString) else {return}
|
||||||
|
load(url)
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Load
|
// MARK: - Load
|
||||||
|
|
||||||
func load(url: NSURL?) {
|
func load(url: NSURL?) {
|
||||||
@ -209,6 +226,14 @@ class MainController: UIViewController {
|
|||||||
searchBar.placeholder = LocalizedStrings.search
|
searchBar.placeholder = LocalizedStrings.search
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func configureUserActivity() {
|
||||||
|
userActivity = userActivity ?? NSUserActivity(activityType: activityType)
|
||||||
|
guard let article = article else {return}
|
||||||
|
userActivity?.title = article.title
|
||||||
|
userActivity?.userInfo = ["ArticleURL": article.url]
|
||||||
|
userActivity?.becomeCurrent()
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Buttons
|
// MARK: - Buttons
|
||||||
|
|
||||||
|
@ -24,12 +24,13 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func webViewDidStartLoad(webView: UIWebView) {
|
func webViewDidStartLoad(webView: UIWebView) {
|
||||||
URLResponseCache.shared.start()
|
// URLResponseCache.shared.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
func webViewDidFinishLoad(webView: UIWebView) {
|
func webViewDidFinishLoad(webView: UIWebView) {
|
||||||
URLResponseCache.shared.stop()
|
// URLResponseCache.shared.stop()
|
||||||
|
|
||||||
|
// Create article object
|
||||||
guard let url = webView.request?.URL,
|
guard let url = webView.request?.URL,
|
||||||
let article = Article.addOrUpdate(url: url, context: NSManagedObjectContext.mainQueueContext) else {return}
|
let article = Article.addOrUpdate(url: url, context: NSManagedObjectContext.mainQueueContext) else {return}
|
||||||
article.title = JSInjection.getTitle(from: webView)
|
article.title = JSInjection.getTitle(from: webView)
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.8.156</string>
|
<string>1.8.223</string>
|
||||||
<key>ITSAppUsesNonExemptEncryption</key>
|
<key>ITSAppUsesNonExemptEncryption</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
@ -69,6 +69,10 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
|
<key>NSUserActivityTypes</key>
|
||||||
|
<array>
|
||||||
|
<string>org.kiwix.kiwix.article-view</string>
|
||||||
|
</array>
|
||||||
<key>UIApplicationShortcutItems</key>
|
<key>UIApplicationShortcutItems</key>
|
||||||
<array>
|
<array>
|
||||||
<dict>
|
<dict>
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.8.158</string>
|
<string>1.8.225</string>
|
||||||
<key>NSExtension</key>
|
<key>NSExtension</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSExtensionMainStoryboard</key>
|
<key>NSExtensionMainStoryboard</key>
|
||||||
|
@ -19,5 +19,53 @@
|
|||||||
landmarkType = "5">
|
landmarkType = "5">
|
||||||
</BreakpointContent>
|
</BreakpointContent>
|
||||||
</BreakpointProxy>
|
</BreakpointProxy>
|
||||||
|
<BreakpointProxy
|
||||||
|
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||||
|
<BreakpointContent
|
||||||
|
shouldBeEnabled = "Yes"
|
||||||
|
ignoreCount = "0"
|
||||||
|
continueAfterRunningActions = "No"
|
||||||
|
filePath = "Kiwix-iOS/AppDelegate.swift"
|
||||||
|
timestampString = "495398189.416709"
|
||||||
|
startingColumnNumber = "9223372036854775807"
|
||||||
|
endingColumnNumber = "9223372036854775807"
|
||||||
|
startingLineNumber = "60"
|
||||||
|
endingLineNumber = "60"
|
||||||
|
landmarkName = "application(application:continueUserActivity:restorationHandler:)"
|
||||||
|
landmarkType = "7">
|
||||||
|
<Locations>
|
||||||
|
<Location
|
||||||
|
shouldBeEnabled = "Yes"
|
||||||
|
ignoreCount = "0"
|
||||||
|
continueAfterRunningActions = "No"
|
||||||
|
symbolName = "Kiwix.AppDelegate.application (__ObjC.UIApplication, continueUserActivity : __ObjC.NSUserActivity, restorationHandler : (Swift.Optional<Swift.Array<Swift.AnyObject>>) -> ()) -> Swift.Bool"
|
||||||
|
moduleName = "Kiwix"
|
||||||
|
usesParentBreakpointCondition = "Yes"
|
||||||
|
urlString = "file:///Volumes/Data/Developer/Kiwix/Kiwix-iOS/AppDelegate.swift"
|
||||||
|
timestampString = "495398559.012676"
|
||||||
|
startingColumnNumber = "9223372036854775807"
|
||||||
|
endingColumnNumber = "9223372036854775807"
|
||||||
|
startingLineNumber = "60"
|
||||||
|
endingLineNumber = "60"
|
||||||
|
offsetFromSymbolStart = "204">
|
||||||
|
</Location>
|
||||||
|
<Location
|
||||||
|
shouldBeEnabled = "Yes"
|
||||||
|
ignoreCount = "0"
|
||||||
|
continueAfterRunningActions = "No"
|
||||||
|
symbolName = "Kiwix.AppDelegate.application (__ObjC.UIApplication, continueUserActivity : __ObjC.NSUserActivity, restorationHandler : (Swift.Optional<Swift.Array<Swift.AnyObject>>) -> ()) -> Swift.Bool"
|
||||||
|
moduleName = "Kiwix"
|
||||||
|
usesParentBreakpointCondition = "Yes"
|
||||||
|
urlString = "file:///Volumes/Data/Developer/Kiwix/Kiwix-iOS/AppDelegate.swift"
|
||||||
|
timestampString = "495398559.013774"
|
||||||
|
startingColumnNumber = "9223372036854775807"
|
||||||
|
endingColumnNumber = "9223372036854775807"
|
||||||
|
startingLineNumber = "60"
|
||||||
|
endingLineNumber = "60"
|
||||||
|
offsetFromSymbolStart = "488">
|
||||||
|
</Location>
|
||||||
|
</Locations>
|
||||||
|
</BreakpointContent>
|
||||||
|
</BreakpointProxy>
|
||||||
</Breakpoints>
|
</Breakpoints>
|
||||||
</Bucket>
|
</Bucket>
|
||||||
|
@ -32,7 +32,7 @@ class Book: NSManagedObject {
|
|||||||
|
|
||||||
book.articleCount = Int64((metadata["articleCount"] as? String) ?? "") ?? 0
|
book.articleCount = Int64((metadata["articleCount"] as? String) ?? "") ?? 0
|
||||||
book.mediaCount = Int64((metadata["mediaCount"] as? String) ?? "") ?? 0
|
book.mediaCount = Int64((metadata["mediaCount"] as? String) ?? "") ?? 0
|
||||||
book.fileSize = Int64((metadata["size"] as? String) ?? "") ?? 0
|
book.fileSize = (Int64((metadata["size"] as? String) ?? "") ?? 0) * 1024
|
||||||
|
|
||||||
book.date = {
|
book.date = {
|
||||||
guard let date = metadata["date"] as? String else {return nil}
|
guard let date = metadata["date"] as? String else {return nil}
|
||||||
|
@ -29,7 +29,7 @@ class RefreshLibraryOperation: GroupOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class Retrive: Operation, ResultOperationType {
|
private class Retrive: Operation, ResultOperationType {
|
||||||
private static let url = NSURL(string: "http://www.kiwix.org/library.xml")!
|
private static let url = NSURL(string: "https://download.kiwix.org/library/library.xml")!
|
||||||
private var result: NSData?
|
private var result: NSData?
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user