Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Added URL scheme support #52 #108

Merged
merged 1 commit into from
Aug 11, 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
26 changes: 15 additions & 11 deletions Source/FolioReaderPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,37 +159,37 @@ class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRecogni

func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {

let url = request.URL
guard let url = request.URL else { return false }

if url?.scheme == "highlight" {
if url.scheme == "highlight" {

shouldShowBar = false

let decoded = url?.absoluteString.stringByRemovingPercentEncoding as String!
let decoded = url.absoluteString.stringByRemovingPercentEncoding as String!
let rect = CGRectFromString(decoded.substringFromIndex(decoded.startIndex.advancedBy(12)))

webView.createMenu(options: true)
webView.setMenuVisible(true, andRect: rect)
menuIsVisible = true

return false
} else if url?.scheme == "play-audio" {
} else if url.scheme == "play-audio" {

let decoded = url?.absoluteString.stringByRemovingPercentEncoding as String!
let decoded = url.absoluteString.stringByRemovingPercentEncoding as String!
let playID = decoded.substringFromIndex(decoded.startIndex.advancedBy(13))
let chapter = FolioReader.sharedInstance.readerCenter.getCurrentChapter()
let href = chapter != nil ? chapter!.href : "";
FolioReader.sharedInstance.readerAudioPlayer.playAudio(href, fragmentID: playID)

return false
} else if url?.scheme == "file" {
} else if url.scheme == "file" {

let anchorFromURL = url?.fragment
let anchorFromURL = url.fragment

// Handle internal url
if (url!.path! as NSString).pathExtension != "" {
if (url.path! as NSString).pathExtension != "" {
let base = (book.opfResource.href as NSString).stringByDeletingLastPathComponent
let path = url?.path
let path = url.path
let splitedPath = path!.componentsSeparatedByString(base.isEmpty ? kBookId : base)

// Return to avoid crash
Expand Down Expand Up @@ -220,10 +220,10 @@ class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRecogni
}

return true
} else if url?.scheme == "mailto" {
} else if url.scheme == "mailto" {
print("Email")
return true
} else if request.URL!.absoluteString != "about:blank" && navigationType == .LinkClicked {
} else if url.absoluteString != "about:blank" && url.scheme.containsString("http") && navigationType == .LinkClicked {

if #available(iOS 9.0, *) {
let safariVC = SFSafariViewController(URL: request.URL!)
Expand All @@ -236,7 +236,11 @@ class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRecogni
FolioReader.sharedInstance.readerCenter.presentViewController(nav, animated: true, completion: nil)
}
return false
} else if UIApplication.sharedApplication().canOpenURL(url) {
UIApplication.sharedApplication().openURL(url)
return false
}

return true
}

Expand Down