mirror of
https://github.com/leanote/leanote-ios.git
synced 2025-10-15 07:32:55 +00:00
LeaWebViewController -> WKWebview
This commit is contained in:
@@ -99,8 +99,9 @@
|
|||||||
"scale" : "2x"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "ios-marketing",
|
|
||||||
"size" : "1024x1024",
|
"size" : "1024x1024",
|
||||||
|
"idiom" : "ios-marketing",
|
||||||
|
"filename" : "icon-no-radius.png",
|
||||||
"scale" : "1x"
|
"scale" : "1x"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
BIN
Leanote/Images.xcassets/AppIcon.appiconset/icon-no-radius.png
Normal file
BIN
Leanote/Images.xcassets/AppIcon.appiconset/icon-no-radius.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
@@ -21,7 +21,7 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>2.0</string>
|
<string>2.3</string>
|
||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleURLTypes</key>
|
<key>CFBundleURLTypes</key>
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>200C</string>
|
<string>3095</string>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSAppTransportSecurity</key>
|
<key>NSAppTransportSecurity</key>
|
||||||
@@ -46,6 +46,10 @@
|
|||||||
<key>NSAllowsArbitraryLoads</key>
|
<key>NSAllowsArbitraryLoads</key>
|
||||||
<true/>
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
|
<key>NSCameraUsageDescription</key>
|
||||||
|
<string>App需要您的同意,才能访问相机</string>
|
||||||
|
<key>NSPhotoLibraryUsageDescription</key>
|
||||||
|
<string>App需要您的同意,才能访问相册</string>
|
||||||
<key>UILaunchStoryboardName</key>
|
<key>UILaunchStoryboardName</key>
|
||||||
<string>Launch Screen</string>
|
<string>Launch Screen</string>
|
||||||
<key>UIMainStoryboardFile</key>
|
<key>UIMainStoryboardFile</key>
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<key>AutocorrectionType</key>
|
<key>AutocorrectionType</key>
|
||||||
<string>No</string>
|
<string>No</string>
|
||||||
<key>DefaultValue</key>
|
<key>DefaultValue</key>
|
||||||
<string>2.0 (200C)</string>
|
<string>2.3 (3095)</string>
|
||||||
<key>IsSecure</key>
|
<key>IsSecure</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>Key</key>
|
<key>Key</key>
|
||||||
|
@@ -1,8 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
|
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" colorMatched="YES">
|
||||||
|
<device id="retina4_7" orientation="portrait">
|
||||||
|
<adaptation id="fullscreen"/>
|
||||||
|
</device>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<deployment identifier="iOS"/>
|
<deployment identifier="iOS"/>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
|
||||||
|
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<objects>
|
<objects>
|
||||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="LeaWebViewController">
|
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="LeaWebViewController">
|
||||||
@@ -21,14 +25,15 @@
|
|||||||
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
|
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<webView contentMode="scaleToFill" id="5">
|
<wkWebView contentMode="scaleToFill" id="5">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="320" height="436"/>
|
<rect key="frame" x="0.0" y="0.0" width="320" height="436"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
|
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||||
<connections>
|
<wkWebViewConfiguration key="configuration" allowsInlineMediaPlayback="YES">
|
||||||
<outlet property="delegate" destination="-1" id="22"/>
|
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" audio="YES" video="YES"/>
|
||||||
</connections>
|
<wkPreferences key="preferences"/>
|
||||||
</webView>
|
</wkWebViewConfiguration>
|
||||||
|
</wkWebView>
|
||||||
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="bottom" barStyle="black" id="3">
|
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="bottom" barStyle="black" id="3">
|
||||||
<rect key="frame" x="0.0" y="436" width="320" height="44"/>
|
<rect key="frame" x="0.0" y="436" width="320" height="44"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||||
@@ -53,10 +58,10 @@
|
|||||||
</barButtonItem>
|
</barButtonItem>
|
||||||
<barButtonItem style="plain" systemItem="fixedSpace" id="47"/>
|
<barButtonItem style="plain" systemItem="fixedSpace" id="47"/>
|
||||||
</items>
|
</items>
|
||||||
<color key="tintColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
<color key="tintColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||||
</toolbar>
|
</toolbar>
|
||||||
</subviews>
|
</subviews>
|
||||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||||
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
|
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
|
||||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||||
</view>
|
</view>
|
||||||
@@ -72,9 +77,4 @@
|
|||||||
<image name="icon-chevron-right" width="24" height="24"/>
|
<image name="icon-chevron-right" width="24" height="24"/>
|
||||||
<image name="icon-share-ios" width="24" height="24"/>
|
<image name="icon-share-ios" width="24" height="24"/>
|
||||||
</resources>
|
</resources>
|
||||||
<simulatedMetricsContainer key="defaultSimulatedMetrics">
|
|
||||||
<simulatedStatusBarMetrics key="statusBar"/>
|
|
||||||
<simulatedOrientationMetrics key="orientation"/>
|
|
||||||
<simulatedScreenMetrics key="destination" type="retina4"/>
|
|
||||||
</simulatedMetricsContainer>
|
|
||||||
</document>
|
</document>
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
@import WebKit;
|
||||||
|
|
||||||
@interface LeaWebViewController : UIViewController
|
@interface LeaWebViewController : UIViewController<WKNavigationDelegate>
|
||||||
|
|
||||||
// Interface
|
// Interface
|
||||||
@property (nonatomic, weak) IBOutlet UIWebView *webView;
|
@property (nonatomic, weak) IBOutlet WKWebView *webView;
|
||||||
|
//@property (nonatomic, weak) IBOutlet WKWebView *wkView;
|
||||||
@property (nonatomic, strong) IBOutlet UIToolbar *toolbar;
|
@property (nonatomic, strong) IBOutlet UIToolbar *toolbar;
|
||||||
@property (nonatomic, strong) IBOutlet UIView *loadingView;
|
@property (nonatomic, strong) IBOutlet UIView *loadingView;
|
||||||
@property (nonatomic, strong) IBOutlet UIActivityIndicatorView *activityIndicator;
|
@property (nonatomic, strong) IBOutlet UIActivityIndicatorView *activityIndicator;
|
||||||
|
@@ -10,6 +10,13 @@
|
|||||||
//#import "Constants.h"
|
//#import "Constants.h"
|
||||||
#import "LeaAlert.h"
|
#import "LeaAlert.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
WPWebViewController.m
|
||||||
|
https://github.com/wordpress-mobile/WordPress-iOS/blob/8ff4b5b18c638f6b592018f277616db2734de2cb/WordPress/Classes/Utility/WPWebViewController.m
|
||||||
|
block回调: https://www.jianshu.com/p/d911cd16c100
|
||||||
|
Xcode11-闪退错误Could not instantiate class named WKWebView https://www.bilibili.com/read/cv3184836/
|
||||||
|
*/
|
||||||
|
|
||||||
#import "Common.h"
|
#import "Common.h"
|
||||||
|
|
||||||
// https://github.com/iDay/WeixinActivity
|
// https://github.com/iDay/WeixinActivity
|
||||||
@@ -21,7 +28,7 @@
|
|||||||
|
|
||||||
@class WPReaderDetailViewController;
|
@class WPReaderDetailViewController;
|
||||||
|
|
||||||
@interface LeaWebViewController () <UIWebViewDelegate, UIPopoverControllerDelegate>
|
@interface LeaWebViewController () <UIPopoverControllerDelegate>
|
||||||
|
|
||||||
@property (nonatomic, weak, readonly) UIScrollView *scrollView;
|
@property (nonatomic, weak, readonly) UIScrollView *scrollView;
|
||||||
@property (nonatomic, strong) UIPopoverController *popover;
|
@property (nonatomic, strong) UIPopoverController *popover;
|
||||||
@@ -37,7 +44,8 @@
|
|||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
_webView.delegate = nil;
|
_webView.UIDelegate = nil;
|
||||||
|
_webView.navigationDelegate = nil;
|
||||||
if (_webView.isLoading) {
|
if (_webView.isLoading) {
|
||||||
[_webView stopLoading];
|
[_webView stopLoading];
|
||||||
}
|
}
|
||||||
@@ -53,6 +61,9 @@
|
|||||||
{
|
{
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
|
|
||||||
|
// 加了这一句 delegate才有用 didStartProvisionalNavigation !!!
|
||||||
|
self.webView.navigationDelegate = self;
|
||||||
|
|
||||||
// if (IS_IPHONE) {
|
// if (IS_IPHONE) {
|
||||||
self.navigationItem.title = NSLocalizedString(@"Loading...", @"");
|
self.navigationItem.title = NSLocalizedString(@"Loading...", @"");
|
||||||
// }
|
// }
|
||||||
@@ -107,7 +118,7 @@
|
|||||||
// 右上角分享
|
// 右上角分享
|
||||||
self.optionsButton.enabled = NO;
|
self.optionsButton.enabled = NO;
|
||||||
|
|
||||||
self.webView.scalesPageToFit = YES;
|
// self.webView.scalesPageToFit = YES;
|
||||||
self.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal;
|
self.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal;
|
||||||
|
|
||||||
if (self.url) {
|
if (self.url) {
|
||||||
@@ -238,6 +249,9 @@
|
|||||||
|
|
||||||
- (void)upgradeButtonsAndLabels:(NSTimer*)timer
|
- (void)upgradeButtonsAndLabels:(NSTimer*)timer
|
||||||
{
|
{
|
||||||
|
[self refreshInterface];
|
||||||
|
return;
|
||||||
|
|
||||||
self.backButton.enabled = self.webView.canGoBack;
|
self.backButton.enabled = self.webView.canGoBack;
|
||||||
self.forwardButton.enabled = self.webView.canGoForward;
|
self.forwardButton.enabled = self.webView.canGoForward;
|
||||||
if (!_isLoading) {
|
if (!_isLoading) {
|
||||||
@@ -255,14 +269,16 @@
|
|||||||
|
|
||||||
- (NSString *)getDocumentPermalink
|
- (NSString *)getDocumentPermalink
|
||||||
{
|
{
|
||||||
// return @"hahagetDocumentPermalink";
|
NSString *permaLink = self.webView.URL.absoluteString;
|
||||||
NSString *permaLink = @"";
|
return permaLink;
|
||||||
|
/*
|
||||||
NSURLRequest *currentRequest = [self.webView request];
|
NSURLRequest *currentRequest = [self.webView request];
|
||||||
if ( currentRequest != nil) {
|
if ( currentRequest != nil) {
|
||||||
NSURL *currentURL = [currentRequest URL];
|
NSURL *currentURL = [currentRequest URL];
|
||||||
permaLink = currentURL.absoluteString;
|
permaLink = currentURL.absoluteString;
|
||||||
}
|
}
|
||||||
return permaLink;
|
return permaLink;
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NSString *permaLink = [self.webView stringByEvaluatingJavaScriptFromString:@"Reader2.get_article_permalink();"];
|
NSString *permaLink = [self.webView stringByEvaluatingJavaScriptFromString:@"Reader2.get_article_permalink();"];
|
||||||
@@ -284,12 +300,14 @@
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)getDocumentDesc
|
- (NSString *)getDocumentDesc:(void(^)(NSString *))block
|
||||||
{
|
{
|
||||||
NSString *desc = [self.webView stringByEvaluatingJavaScriptFromString:@"\
|
// 返回之前就要截断不然可能会有内存出错
|
||||||
(function() {try{\
|
NSString *js = @"\
|
||||||
\
|
(function() {\
|
||||||
if(location.href.indexOf('lea.leanote.com') != -1) {\
|
function aaaa () {\
|
||||||
|
try {\
|
||||||
|
if (location.href.indexOf('lea.leanote.com') != -1) {\
|
||||||
var metas = document.getElementsByTagName('meta');\
|
var metas = document.getElementsByTagName('meta');\
|
||||||
for (i = 0; i < metas.length; i++) {\
|
for (i = 0; i < metas.length; i++) {\
|
||||||
if (metas[i].getAttribute('name') == 'description') {\
|
if (metas[i].getAttribute('name') == 'description') {\
|
||||||
@@ -298,21 +316,31 @@
|
|||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
var markdownElem = document.getElementById('markdownContent');\
|
var markdownElem = document.getElementById('markdownContent');\
|
||||||
if(markdownElem) {\
|
if (markdownElem) {\
|
||||||
var textareaElem = markdownElem.getElementsByTagName('textarea');\
|
var textareaElem = markdownElem.getElementsByTagName('textarea');\
|
||||||
if(textareaElem && textareaElem.length) return textareaElem[0].value;\
|
if (textareaElem && textareaElem.length) return textareaElem[0].value;\
|
||||||
}\
|
}\
|
||||||
var content = document.getElementById('content');\
|
var content = document.getElementById('content');\
|
||||||
if(content) {return content.innerText;}\
|
if (content) { return content.innerText.trim().substr(0, 50); }\
|
||||||
var content = document.getElementsByClassName('content');\
|
var content = document.getElementsByClassName('content');\
|
||||||
if(content && content.length) {return content[0].innerText;}\
|
if (content && content.length) { return content[0].innerText; }\
|
||||||
var desc = document.getElementsByClassName('desc');\
|
var desc = document.getElementsByClassName('desc');\
|
||||||
if(desc && desc.length) {return desc[0].innerText;}\
|
if (desc && desc.length) { return desc[0].innerText; }\
|
||||||
return document.getElementsByTagName('body')[0].innerText;\
|
return document.getElementsByTagName('body')[0].innerText;\
|
||||||
\
|
\
|
||||||
} catch(e){return ""}\
|
} catch (e) { return ""; }\
|
||||||
\
|
}\
|
||||||
})();"];
|
var content = aaaa();\
|
||||||
|
return (content || '').trim().substr(0, 50);\
|
||||||
|
})();\
|
||||||
|
";
|
||||||
|
//执行JS
|
||||||
|
[self.webView evaluateJavaScript:js completionHandler:^(id _Nullable result, NSError * _Nullable error) {
|
||||||
|
NSLog(@"get desc ret %@ %@", error, result);
|
||||||
|
if (error == nil) {
|
||||||
|
if (result != nil) {
|
||||||
|
NSString *desc = [NSString stringWithFormat:@"%@", result];
|
||||||
|
NSLog(@"desc %@", desc);
|
||||||
// desc 多了, 不能调微信发送给朋友了
|
// desc 多了, 不能调微信发送给朋友了
|
||||||
if ( desc != nil && [[desc trim] isEqualToString:@""] == NO) {
|
if ( desc != nil && [[desc trim] isEqualToString:@""] == NO) {
|
||||||
[desc stringByReplacingOccurrencesOfString:@"\n" withString:@""];
|
[desc stringByReplacingOccurrencesOfString:@"\n" withString:@""];
|
||||||
@@ -320,22 +348,34 @@
|
|||||||
desc = [desc substringToIndex:47];
|
desc = [desc substringToIndex:47];
|
||||||
}
|
}
|
||||||
desc = [NSString stringWithFormat:@"%@...", desc];
|
desc = [NSString stringWithFormat:@"%@...", desc];
|
||||||
return desc;
|
// return desc;
|
||||||
|
block(desc);
|
||||||
|
} else {
|
||||||
|
block(@"...");
|
||||||
}
|
}
|
||||||
return @"";
|
} else {
|
||||||
|
block(@"...");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
NSLog(@"evaluateJavaScript error : %@", error.localizedDescription);
|
||||||
|
block(@"...");
|
||||||
|
}
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)getDocumentTitle
|
- (NSString *)getDocumentTitle
|
||||||
{
|
{
|
||||||
// load the title from the document
|
if (self.webView == nil) {
|
||||||
NSString *title = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"];
|
NSLog(@"webview is nillllllllllll");
|
||||||
|
return @"";
|
||||||
|
}
|
||||||
|
NSString *title = self.webView.title;
|
||||||
|
|
||||||
if ( title != nil && [[title trim] isEqualToString:@""] == NO) {
|
if (title != nil && [[title trim] isEqualToString:@""] == NO) {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString* permaLink = [self getDocumentPermalink];
|
return [self getDocumentPermalink] ?: [NSString string];
|
||||||
return ( permaLink != nil) ? permaLink : @"";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)loadURL:(NSURL *)webURL
|
- (void)loadURL:(NSURL *)webURL
|
||||||
@@ -453,8 +493,10 @@
|
|||||||
// 后退
|
// 后退
|
||||||
- (void)goBack
|
- (void)goBack
|
||||||
{
|
{
|
||||||
|
[self.webView goBack];
|
||||||
|
/*
|
||||||
if (self.detailContent != nil) {
|
if (self.detailContent != nil) {
|
||||||
NSString *prevItemAvailable = [self.webView stringByEvaluatingJavaScriptFromString:@"Reader2.show_prev_item();"];
|
NSString *prevItemAvailable = [self.webView evaluateJavaScript:@"Reader2.show_prev_item();"];
|
||||||
if ( [prevItemAvailable rangeOfString:@"true"].location == NSNotFound ) {
|
if ( [prevItemAvailable rangeOfString:@"true"].location == NSNotFound ) {
|
||||||
self.backButton.enabled = NO;
|
self.backButton.enabled = NO;
|
||||||
} else {
|
} else {
|
||||||
@@ -478,13 +520,17 @@
|
|||||||
}
|
}
|
||||||
[self.webView goBack];
|
[self.webView goBack];
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// 前进
|
// 前进
|
||||||
- (void)goForward
|
- (void)goForward
|
||||||
{
|
{
|
||||||
|
[self.webView goForward];
|
||||||
|
/*
|
||||||
if (self.detailContent != nil) {
|
if (self.detailContent != nil) {
|
||||||
NSString *nextItemAvailable = [self.webView stringByEvaluatingJavaScriptFromString:@"Reader2.show_next_item();"];
|
NSString *nextItemAvailable = [self.webView evaluateJavaScript:@"Reader2.show_next_item();" completionHandler:nil];
|
||||||
|
|
||||||
if ([nextItemAvailable rangeOfString:@"true"].location == NSNotFound) {
|
if ([nextItemAvailable rangeOfString:@"true"].location == NSNotFound) {
|
||||||
self.forwardButton.enabled = NO;
|
self.forwardButton.enabled = NO;
|
||||||
} else {
|
} else {
|
||||||
@@ -506,6 +552,7 @@
|
|||||||
}
|
}
|
||||||
[self.webView goForward];
|
[self.webView goForward];
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)showLinkOptions
|
- (void)showLinkOptions
|
||||||
@@ -513,7 +560,10 @@
|
|||||||
NSString* permaLink = [self getDocumentPermalink];
|
NSString* permaLink = [self getDocumentPermalink];
|
||||||
|
|
||||||
NSString *title = [self getDocumentTitle];
|
NSString *title = [self getDocumentTitle];
|
||||||
NSString *desc = [self getDocumentDesc];
|
[self getDocumentDesc:^(NSString *desc){
|
||||||
|
|
||||||
|
NSLog(@"showLinkOptions desc: %@", desc);
|
||||||
|
|
||||||
NSMutableArray *activityItems = [NSMutableArray array];
|
NSMutableArray *activityItems = [NSMutableArray array];
|
||||||
if (title) {
|
if (title) {
|
||||||
[activityItems addObject:title];
|
[activityItems addObject:title];
|
||||||
@@ -527,7 +577,7 @@
|
|||||||
|
|
||||||
[activityItems addObject:[NSURL URLWithString:permaLink]];
|
[activityItems addObject:[NSURL URLWithString:permaLink]];
|
||||||
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:activities];
|
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:activities];
|
||||||
// activityViewController.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePrint];
|
// activityViewController.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePrint];
|
||||||
if (title) {
|
if (title) {
|
||||||
[activityViewController setValue:title forKey:@"subject"];
|
[activityViewController setValue:title forKey:@"subject"];
|
||||||
}
|
}
|
||||||
@@ -535,7 +585,7 @@
|
|||||||
if (!completed) {
|
if (!completed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// [WPActivityDefaults trackActivityType:activityType];
|
// [WPActivityDefaults trackActivityType:activityType];
|
||||||
};
|
};
|
||||||
|
|
||||||
if (IS_IPAD) {
|
if (IS_IPAD) {
|
||||||
@@ -549,6 +599,7 @@
|
|||||||
} else {
|
} else {
|
||||||
[self presentViewController:activityViewController animated:YES completion:nil];
|
[self presentViewController:activityViewController animated:YES completion:nil];
|
||||||
}
|
}
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reload
|
- (void)reload
|
||||||
@@ -590,6 +641,93 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)refreshInterface
|
||||||
|
{
|
||||||
|
self.backButton.enabled = self.webView.canGoBack;
|
||||||
|
self.forwardButton.enabled = self.webView.canGoForward;
|
||||||
|
|
||||||
|
if (IS_IPAD) {
|
||||||
|
if (self.navigationController.navigationBarHidden == NO) {
|
||||||
|
self.title = [self getDocumentTitle];
|
||||||
|
} else {
|
||||||
|
[self.iPadNavBar.topItem setTitle:[self getDocumentTitle]];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.navigationItem.title = [self getDocumentTitle];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([self.webView.URL.absoluteString isEqualToString:@""]) {
|
||||||
|
self.optionsButton.enabled = FALSE;
|
||||||
|
} else {
|
||||||
|
self.optionsButton.enabled = !self.webView.loading;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - WKNavigationDelegate
|
||||||
|
|
||||||
|
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
|
||||||
|
NSLog(@"didStartProvisionalNavigation!!!!......................");
|
||||||
|
[self setLoading:YES];
|
||||||
|
}
|
||||||
|
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation
|
||||||
|
{
|
||||||
|
NSLog(@"didFinishNavigation!!!!!!!......................");
|
||||||
|
[self setLoading:NO];
|
||||||
|
[self refreshInterface];
|
||||||
|
[webView evaluateJavaScript:@"var a = document.getElementsByTagName('a');for(var i=0;i<a.length;i++){a[i].setAttribute('target','');}" completionHandler:nil];
|
||||||
|
}
|
||||||
|
- (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error
|
||||||
|
{
|
||||||
|
NSLog(@"didFailNavigation!!!!......................");
|
||||||
|
[self setLoading:NO];
|
||||||
|
[self refreshInterface];
|
||||||
|
}
|
||||||
|
|
||||||
|
// _blank处理
|
||||||
|
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
|
||||||
|
{
|
||||||
|
NSURLRequest *request = [navigationAction request];
|
||||||
|
|
||||||
|
NSLog(@"%@ Should Start Loading [%@]", NSStringFromClass([self class]), request.URL.absoluteString);
|
||||||
|
|
||||||
|
// To handle WhatsApp and Telegraph shares
|
||||||
|
// Even though the documentation says that canOpenURL will only return YES for
|
||||||
|
// URLs configured on the plist under LSApplicationQueriesSchemes if we don't filter
|
||||||
|
// out http requests it also returns YES for those
|
||||||
|
if (![request.URL.scheme hasPrefix:@"http"]
|
||||||
|
&& [[UIApplication sharedApplication] canOpenURL:request.URL]) {
|
||||||
|
[[UIApplication sharedApplication] openURL:request.URL
|
||||||
|
options:nil
|
||||||
|
completionHandler:nil];
|
||||||
|
|
||||||
|
decisionHandler(WKNavigationActionPolicyCancel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WKFrameInfo *frameInfo = navigationAction.targetFrame;
|
||||||
|
if (![frameInfo isMainFrame]) {
|
||||||
|
[webView loadRequest:navigationAction.request];
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (self.navigationDelegate != nil) {
|
||||||
|
// WebNavigationPolicy *policy = [self.navigationDelegate shouldNavigateWithRequest:request];
|
||||||
|
//
|
||||||
|
// if (policy.redirectRequest != NULL) {
|
||||||
|
// [self.webView loadRequest:policy.redirectRequest];
|
||||||
|
// decisionHandler(WKNavigationActionPolicyCancel);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// decisionHandler(policy.action);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
[self refreshInterface];
|
||||||
|
|
||||||
|
decisionHandler(WKNavigationActionPolicyAllow);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - UIPopover Delegate
|
#pragma mark - UIPopover Delegate
|
||||||
|
|
||||||
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
|
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
|
||||||
@@ -597,6 +735,7 @@
|
|||||||
self.popover = nil;
|
self.popover = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
#pragma mark - UIWebViewDelegate
|
#pragma mark - UIWebViewDelegate
|
||||||
|
|
||||||
- (BOOL)webView:(UIWebView *)webView
|
- (BOOL)webView:(UIWebView *)webView
|
||||||
@@ -620,6 +759,8 @@
|
|||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSLog(@"reloading......................");
|
||||||
|
|
||||||
[self setLoading:YES];
|
[self setLoading:YES];
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
@@ -647,13 +788,14 @@
|
|||||||
[self setLoading:NO];
|
[self setLoading:NO];
|
||||||
|
|
||||||
CGSize webviewSize = self.view.frame.size;
|
CGSize webviewSize = self.view.frame.size;
|
||||||
/*
|
|
||||||
NSString *js = [NSString stringWithFormat:@"var meta = document.createElement('meta');meta.setAttribute( 'name', 'viewport' ); meta.setAttribute( 'content', 'width = %d, initial-scale = 1.0, user-scalable = yes' );document.getElementsByTagName('head')[0].appendChild(meta)", webviewSize.width];
|
|
||||||
[aWebView stringByEvaluatingJavaScriptFromString: js];
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!self.hasLoadedContent/* &&
|
// NSString *js = [NSString stringWithFormat:@"var meta = document.createElement('meta');meta.setAttribute( 'name', 'viewport' ); meta.setAttribute( 'content', 'width = %d, initial-scale = 1.0, user-scalable = yes' );document.getElementsByTagName('head')[0].appendChild(meta)", webviewSize.width];
|
||||||
([aWebView.request.URL.absoluteString rangeOfString:WPMobileReaderDetailURL].location == NSNotFound || self.detailContent)*/) {
|
// [aWebView stringByEvaluatingJavaScriptFromString: js];
|
||||||
|
|
||||||
|
|
||||||
|
// &&
|
||||||
|
([aWebView.request.URL.absoluteString rangeOfString:WPMobileReaderDetailURL].location == NSNotFound || self.detailContent)
|
||||||
|
if (!self.hasLoadedContent) {
|
||||||
[aWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"Reader2.set_loaded_items(%@);", self.readerAllItems]];
|
[aWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"Reader2.set_loaded_items(%@);", self.readerAllItems]];
|
||||||
[aWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"Reader2.show_article_details(%@);", self.detailContent]];
|
[aWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"Reader2.show_article_details(%@);", self.detailContent]];
|
||||||
|
|
||||||
@@ -700,6 +842,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - Requests Helpers
|
#pragma mark - Requests Helpers
|
||||||
|
|
||||||
@@ -757,7 +901,7 @@
|
|||||||
f.submit(); \
|
f.submit(); \
|
||||||
})('%@', '%@', '%@');", host, email, pwd];
|
})('%@', '%@', '%@');", host, email, pwd];
|
||||||
// NSLog(@"%@", loginJs);
|
// NSLog(@"%@", loginJs);
|
||||||
[self.webView stringByEvaluatingJavaScriptFromString:loginJs];
|
[self.webView evaluateJavaScript:loginJs completionHandler:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@@ -82,4 +82,4 @@ SPEC CHECKSUMS:
|
|||||||
|
|
||||||
PODFILE CHECKSUM: a0c7b39c9e76e3f168d832581dc99f6e9937b67b
|
PODFILE CHECKSUM: a0c7b39c9e76e3f168d832581dc99f6e9937b67b
|
||||||
|
|
||||||
COCOAPODS: 1.6.0
|
COCOAPODS: 1.6.1
|
||||||
|
Reference in New Issue
Block a user