这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 8 additions & 8 deletions Source/URL+Preview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ public extension URL {

func fetchPageInfo(_ completion: @escaping ((_ title: String?, _ description: String?, _ previewImage: String?) -> Void), failure: @escaping ((_ errorMessage: String) -> Void)) {

let request = NSMutableURLRequest(url: self)
var request = URLRequest(url: self)

let newUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36"
request.setValue(newUserAgent, forHTTPHeaderField: "User-Agent")
ValidationQueue.queue.cancelAllOperations()

NSURLConnection.sendAsynchronousRequest(request as URLRequest, queue: ValidationQueue.queue, completionHandler: { (response: URLResponse?, data: Data?, error: Error?) -> Void in
request.setValue(newUserAgent, forHTTPHeaderField: "User-Agent")

URLSession.shared.dataTask(with: request) { (data, response, error) in
if error != nil {
DispatchQueue.main.async(execute: {
failure("Url receive no response")
Expand All @@ -42,13 +43,13 @@ public extension URL {
if let nodes = doc.head?.xpath("//meta").enumerated() {
for node in nodes {
if node.element["property"]?.contains("description") == true ||
node.element["name"] == "description" {
node.element["name"] == "description" {
description = node.element["content"]
}

if node.element["property"]?.contains("image") == true &&
node.element["content"]?.contains("http") == true {
previewImage = node.element["content"]
previewImage = node.element["content"]
}
}
}
Expand All @@ -57,7 +58,6 @@ public extension URL {
completion(title, description, previewImage)
})
}

}
} else {
DispatchQueue.main.async(execute: {
Expand All @@ -66,6 +66,6 @@ public extension URL {
return
}
}
})
}.resume()
}
}
2 changes: 1 addition & 1 deletion URLPreview.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Pod::Spec.new do |s|

s.source_files = "Source"
s.framework = "UIKit"
s.dependency 'Kanna', '~> 4.0.0'
s.dependency 'Kanna', '~> 5.2.2'
s.requires_arc = true
s.swift_versions = ['3.2', '4.0', '4.2', '5']

Expand Down
2 changes: 1 addition & 1 deletion UrlPreviewDemo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ platform :ios, '8.0'
use_frameworks!

target 'UrlPreviewDemo' do
pod 'Kanna', '~> 4.0.0'
pod 'Kanna'
end

8 changes: 4 additions & 4 deletions UrlPreviewDemo/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ PODS:
- Kanna (4.0.3)

DEPENDENCIES:
- Kanna (~> 4.0.0)
- Kanna

SPEC REPOS:
https://github.com/cocoapods/specs.git:
https://github.com/CocoaPods/Specs.git:
- Kanna

SPEC CHECKSUMS:
Kanna: 0ebbdd0e7e3308f0aafbd569e79c8cadc5eb877c

PODFILE CHECKSUM: f80d3c451bd0a3a4c36007f7ed84b0c2d1648651
PODFILE CHECKSUM: fc94f85c5505ab4fb9c30c9187b66902876eabc7

COCOAPODS: 1.7.0
COCOAPODS: 1.9.3

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions UrlPreviewDemo/UrlPreviewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = UrlPreviewDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.ichigo.UrlPreviewDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -368,6 +369,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = UrlPreviewDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.ichigo.UrlPreviewDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,52 @@
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Loading