Skip to content

Commit

Permalink
#1270 (replacing UIWebView with WKWebView)
Browse files Browse the repository at this point in the history
- All app-specific uses of UIWebView have been replaced with WKWebView.
- Some third-party uses remain.
- More testing required.
- Note that I’ve bumped the minimum iOS version to iOS 11, since that is needed for WKWebView support.
- Committing to a new branch until ready.
  • Loading branch information
Dejal committed Feb 23, 2020
1 parent 1692e58 commit 383384b
Show file tree
Hide file tree
Showing 20 changed files with 399 additions and 563 deletions.
5 changes: 3 additions & 2 deletions clients/ios/Classes/AuthorizeServicesViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
//

#import <UIKit/UIKit.h>
@import WebKit;

@class NewsBlurAppDelegate;

@interface AuthorizeServicesViewController : UIViewController <UIWebViewDelegate> {
@interface AuthorizeServicesViewController : UIViewController <WKNavigationDelegate> {
NewsBlurAppDelegate *appDelegate;
NSString *url;
NSString *type;
Expand All @@ -22,7 +23,7 @@
@property (nonatomic) NSString *type;
@property (nonatomic, readwrite) BOOL fromStory;

@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet WKWebView *webView;

- (void)doCancelButton;
- (void)showError:(NSString *)error;
Expand Down
84 changes: 42 additions & 42 deletions clients/ios/Classes/AuthorizeServicesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.appDelegate = (NewsBlurAppDelegate *)[[UIApplication sharedApplication] delegate];
self.webView.delegate = self;
}

- (void)viewDidUnload {
Expand All @@ -53,11 +52,14 @@ - (void)viewWillAppear:(BOOL)animated {
} else if ([type isEqualToString:@"twitter"]) {
self.navigationItem.title = @"Twitter";
}
NSString *urlAddress = [NSString stringWithFormat:@"%@%@", self.appDelegate.url, url];
NSURL *fullUrl = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:fullUrl];
[self.webView loadRequest:requestObj];


[self.appDelegate prepareWebView:self.webView completionHandler:^{
NSString *urlAddress = [NSString stringWithFormat:@"%@%@", self.appDelegate.url, url];
NSURL *fullUrl = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:fullUrl];
[self.webView loadRequest:requestObj];
}];

if (self.fromStory && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
initWithTitle: @"Cancel"
Expand All @@ -79,51 +81,49 @@ - (void)doCancelButton {
[appDelegate.modalNavigationController dismissViewControllerAnimated:YES completion:nil];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
NSURLRequest *request = navigationAction.request;
NSString *URLString = [[request URL] absoluteString];
NSLog(@"URL STRING IS %@", URLString);

// Look at the host & path to cope with http:// or https:// schemes
if ([request.URL.host isEqualToString:self.appDelegate.host] && [request.URL.path isEqualToString:@"/"]) {
NSString *error = [self.webView stringByEvaluatingJavaScriptFromString:@"NEWSBLUR.error"];

if (self.fromStory) {
[appDelegate refreshUserProfile:^{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[appDelegate.shareNavigationController viewWillAppear:YES];
[appDelegate.modalNavigationController dismissViewControllerAnimated:YES completion:nil];
} else {
[self.navigationController popViewControllerAnimated:YES];
}
}];
} else {
[self.navigationController popViewControllerAnimated:YES];
if ([type isEqualToString:@"facebook"]) {
if (error.length) {
[self showError:error];
} else {
[appDelegate.firstTimeUserAddFriendsViewController selectFacebookButton];
}
} else if ([type isEqualToString:@"twitter"]) {
if (error.length) {
[self showError:error];
} else {
[appDelegate.firstTimeUserAddFriendsViewController selectTwitterButton];
[self.webView evaluateJavaScript:@"NEWSBLUR.error" completionHandler:^(id result, NSError *error) {
NSString *errorString = result;

if (self.fromStory) {
[appDelegate refreshUserProfile:^{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[appDelegate.shareNavigationController viewWillAppear:YES];
[appDelegate.modalNavigationController dismissViewControllerAnimated:YES completion:nil];
} else {
[self.navigationController popViewControllerAnimated:YES];
}
}];
} else {
[self.navigationController popViewControllerAnimated:YES];
if ([type isEqualToString:@"facebook"]) {
if (errorString.length) {
[self showError:errorString];
} else {
[appDelegate.firstTimeUserAddFriendsViewController selectFacebookButton];
}
} else if ([type isEqualToString:@"twitter"]) {
if (errorString.length) {
[self showError:errorString];
} else {
[appDelegate.firstTimeUserAddFriendsViewController selectTwitterButton];
}
}
}
}
return NO;

decisionHandler(WKNavigationActionPolicyCancel);
}];

return;
}

// // for failed google reader authorization
// if ([URLString hasPrefix:[NSString stringWithFormat:@"%@/import/callback", self.appDelegate.url]]) {
// [self.navigationController popViewControllerAnimated:YES];
// [appDelegate.firstTimeUserAddSitesViewController importFromGoogleReaderFailed];
// return NO;
// }


return YES;
decisionHandler(WKNavigationActionPolicyAllow);
}

- (void)showError:(NSString *)error {
Expand Down
208 changes: 40 additions & 168 deletions clients/ios/Classes/AuthorizeServicesViewController.xib
Original file line number Diff line number Diff line change
@@ -1,169 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1296</int>
<string key="IBDocument.SystemVersion">11E53</string>
<string key="IBDocument.InterfaceBuilderVersion">2182</string>
<string key="IBDocument.AppKitVersion">1138.47</string>
<string key="IBDocument.HIToolboxVersion">569.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">1181</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBProxyObject</string>
<string>IBUIView</string>
<string>IBUIWebView</string>
</array>
<array key="IBDocument.PluginDependencies">
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</array>
<object class="NSMutableDictionary" key="IBDocument.Metadata">
<string key="NS.key.0">PluginDependencyRecalculationVersion</string>
<integer value="1" key="NS.object.0"/>
</object>
<array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
<object class="IBProxyObject" id="372490531">
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBProxyObject" id="975951072">
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIView" id="191373211">
<reference key="NSNextResponder"/>
<int key="NSvFlags">274</int>
<array class="NSMutableArray" key="NSSubviews">
<object class="IBUIWebView" id="464701441">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">274</int>
<string key="NSFrameSize">{320, 460}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDEAA</bytes>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIDataDetectorTypes">1</int>
<bool key="IBUIDetectsPhoneNumbers">YES</bool>
</object>
</array>
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="464701441"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
<object class="NSColorSpace" key="NSCustomColorSpace">
<int key="NSID">2</int>
</object>
</object>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
</array>
<object class="IBObjectContainer" key="IBDocument.Objects">
<array class="NSMutableArray" key="connectionRecords">
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">view</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="191373211"/>
</object>
<int key="connectionID">3</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">webView</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="464701441"/>
</object>
<int key="connectionID">5</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
<object class="IBObjectRecord">
<int key="objectID">0</int>
<array key="object" id="0"/>
<reference key="children" ref="1000"/>
<nil key="parent"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">1</int>
<reference key="object" ref="191373211"/>
<array class="NSMutableArray" key="children">
<reference ref="464701441"/>
</array>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">-1</int>
<reference key="object" ref="372490531"/>
<reference key="parent" ref="0"/>
<string key="objectName">File's Owner</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">-2</int>
<reference key="object" ref="975951072"/>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">4</int>
<reference key="object" ref="464701441"/>
<reference key="parent" ref="191373211"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
<string key="-1.CustomClassName">AuthorizeServicesViewController</string>
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="-2.CustomClassName">UIResponder</string>
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="4.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">5</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">AuthorizeServicesViewController</string>
<string key="superclassName">UIViewController</string>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">webView</string>
<string key="NS.object.0">UIWebView</string>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<string key="NS.key.0">webView</string>
<object class="IBToOneOutletInfo" key="NS.object.0">
<string key="name">webView</string>
<string key="candidateClassName">UIWebView</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/AuthorizeServicesViewController.h</string>
</object>
</object>
</array>
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
<real value="1296" key="NS.object.0"/>
</object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">1181</string>
</data>
</archive>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="AuthorizeServicesViewController">
<connections>
<outlet property="view" destination="1" id="3"/>
<outlet property="webView" destination="8UG-TA-0d6" id="Opa-nd-RBg"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="1">
<rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<wkWebView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="8UG-TA-0d6">
<rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
<color key="backgroundColor" red="0.36078431370000003" green="0.38823529410000002" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<wkWebViewConfiguration key="configuration">
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
<wkPreferences key="preferences"/>
</wkWebViewConfiguration>
</wkWebView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="8UG-TA-0d6" secondAttribute="trailing" id="0fo-lT-jLv"/>
<constraint firstItem="8UG-TA-0d6" firstAttribute="top" secondItem="1" secondAttribute="top" id="GZ6-CK-IVu"/>
<constraint firstItem="8UG-TA-0d6" firstAttribute="leading" secondItem="1" secondAttribute="leading" id="HyD-aX-iiL"/>
<constraint firstAttribute="bottom" secondItem="8UG-TA-0d6" secondAttribute="bottom" id="I22-f0-3Fi"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="-441" y="53"/>
</view>
</objects>
</document>
4 changes: 1 addition & 3 deletions clients/ios/Classes/DashboardViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
@class FeedbackModule;
@class FeedDetailViewController;

@interface DashboardViewController : UIViewController <UIPopoverControllerDelegate, UIWebViewDelegate> {
@interface DashboardViewController : UIViewController <UIPopoverControllerDelegate> {
NewsBlurAppDelegate *appDelegate;
InteractionsModule *interactionsModule;
ActivityModule *activitiesModule;
FeedDetailViewController *storiesModule;
UIWebView *feedbackWebView;
UIToolbar *toolbar;
NBDashboardNavigationBar *topToolbar;
UISegmentedControl *segmentedButton;
Expand All @@ -30,7 +29,6 @@
@property (nonatomic) IBOutlet InteractionsModule *interactionsModule;
@property (nonatomic) IBOutlet ActivityModule *activitiesModule;
@property (nonatomic) IBOutlet FeedDetailViewController *storiesModule;
@property (nonatomic) IBOutlet UIWebView *feedbackWebView;

@property (nonatomic) IBOutlet NBDashboardNavigationBar *topToolbar;
@property (nonatomic) IBOutlet UIToolbar *toolbar;
Expand Down
Loading

2 comments on commit 383384b

@samuelclay
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a note, I submitted v10.0.1 right before this commit, which includes some iPad fixes and theme changes.

@Dejal
Copy link
Collaborator Author

@Dejal Dejal commented on 383384b Feb 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. This commit isn't ready for prime-time yet, hence the new branch.

Please sign in to comment.