Skip to content

Commit 06f4112

Browse files
authored
Swift5 (#1)
* Change to Swift 5 for DemoApp. * Try upload different TwitterKit.framework. * Update README.md. Update Swift version for TwitterKitTest. * Try to remove UIWebView. * Try to migrate to WKWebView. * Add setScalesPageToFit to WKWebView; Clean up the code. * Move TwitterKit.podspec to root folder. * Add new pod, TwitterKit5.podspec.
1 parent ac42e13 commit 06f4112

19 files changed

+133
-41
lines changed

DemoApp/DemoApp.xcodeproj/project.pbxproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@
544544
developmentRegion = English;
545545
hasScannedForEncodings = 0;
546546
knownRegions = (
547+
English,
547548
en,
548549
Base,
549550
);
@@ -926,7 +927,7 @@
926927
PROVISIONING_PROFILE_SPECIFIER = "";
927928
SWIFT_OBJC_BRIDGING_HEADER = "DemoApp/DemoApp-Bridging-Header.h";
928929
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
929-
SWIFT_VERSION = 3.0;
930+
SWIFT_VERSION = 5.0;
930931
};
931932
name = Debug;
932933
};
@@ -947,7 +948,7 @@
947948
PRODUCT_NAME = "$(TARGET_NAME)";
948949
PROVISIONING_PROFILE_SPECIFIER = "";
949950
SWIFT_OBJC_BRIDGING_HEADER = "DemoApp/DemoApp-Bridging-Header.h";
950-
SWIFT_VERSION = 3.0;
951+
SWIFT_VERSION = 5.0;
951952
};
952953
name = Release;
953954
};

DemoApp/DemoApp/Authentication/AuthenticationViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class AuthenticationViewController: UIViewController {
7676

7777
// MARK: - Actions
7878

79-
func home() {
79+
@objc func home() {
8080
delegate?.authenticationViewControllerDidTapHome(viewController: self)
8181
}
8282

DemoApp/DemoApp/Authentication/LoginViewController.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ class LoginViewController: UIViewController {
120120

121121
// MARK: - Actions
122122

123-
func backgroundTap() {
123+
@objc func backgroundTap() {
124124
dismiss(animated: true, completion: nil)
125125
}
126126

127-
func login() {
127+
@objc func login() {
128128
TWTRTwitter.sharedInstance().logIn(with: self) { (session, error) in
129129
if let session = session {
130130
self.dismiss(animated: true) {
@@ -136,7 +136,7 @@ class LoginViewController: UIViewController {
136136
}
137137
}
138138

139-
func clearAccounts() {
139+
@objc func clearAccounts() {
140140
for session in TWTRTwitter.sharedInstance().sessionStore.existingUserSessions() {
141141
if let session = session as? TWTRSession {
142142
TWTRTwitter.sharedInstance().sessionStore.logOutUserID(session.userID)

DemoApp/DemoApp/Authentication/TwitterLoginCollectionViewCell.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class TwitterLoginCollectionViewCell: UICollectionViewCell {
4848

4949
// MARK: - Actions
5050

51-
func addAccount() {
51+
@objc func addAccount() {
5252
delegate?.loginCollectionViewCellDidTapAddAccountButton(cell: self)
5353
}
5454

DemoApp/DemoApp/Authentication/TwitterSessionCollectionViewCell.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class TwitterSessionCollectionViewCell: UICollectionViewCell {
112112

113113
// MARK: - Actions
114114

115-
func logout() {
115+
@objc func logout() {
116116
if let session = session {
117117
delegate?.sessionCollectionViewCell(collectionViewCell: self, didTapLogoutFor: session)
118118
}

DemoApp/DemoApp/Demos/Complex Tweet Demo/TweetComposerViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ extension TweetComposerViewController: UIImagePickerControllerDelegate, UINaviga
151151
}
152152
}
153153

154-
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
154+
private func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
155155
picker.dismiss(animated: true)
156-
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
156+
if let image = info[UIImagePickerController.InfoKey.originalImage.rawValue] as? UIImage {
157157
let composer = TWTRComposerViewController(initialText: "Check out this great image: ", image: image, videoURL: nil)
158158
composer.delegate = self
159159
self.present(composer, animated: true)

DemoApp/DemoApp/Demos/Timelines Demo/ESPNTimelineViewController.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ class ESPNTimelineViewController: TWTRTimelineViewController {
4444
@available(iOS 8.0, *)
4545
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
4646

47-
let moreRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "More", handler:{action, indexpath in
47+
let moreRowAction = UITableViewRowAction(style: UITableViewRowAction.Style.default, title: "More", handler:{action, indexpath in
4848
print("More Action")
4949
})
5050
moreRowAction.backgroundColor = UIColor(red: 0.298, green: 0.851, blue: 0.3922, alpha: 1.0);
5151

52-
let deleteRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "Delete", handler:{action, indexpath in
52+
let deleteRowAction = UITableViewRowAction(style: UITableViewRowAction.Style.default, title: "Delete", handler:{action, indexpath in
5353
print("Delete Action")
5454
});
5555

5656
return [deleteRowAction, moreRowAction]
5757
}
5858

59-
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
59+
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
6060

6161
}
6262

DemoApp/DemoApp/Demos/Timelines Demo/SearchTimelineViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class SearchTimelineViewController: TWTRTimelineViewController, DZNEmptyDataSetS
3030

3131
func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString {
3232
let text = "Could not find Tweets.";
33-
let attributes = [NSFontAttributeName: UIFont.boldSystemFont(ofSize: 18),
34-
NSForegroundColorAttributeName: UIColor.darkGray]
33+
let attributes = [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 18),
34+
NSAttributedString.Key.foregroundColor: UIColor.darkGray]
3535

3636
return NSAttributedString(string: text, attributes: attributes)
3737
}

DemoApp/DemoApp/Demos/TweetView demo/TweetOptionTableViewCell.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class TweetOptionTableViewCell: UITableViewCell {
3232

3333
// MARK: - Init
3434

35-
required override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
35+
required override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
3636
super.init(style: style, reuseIdentifier: reuseIdentifier)
3737

3838
contentView.addSubview(titleLabel)

DemoApp/DemoApp/Demos/TweetView demo/TweetViewStylerViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class TweetViewStylerViewController: UIViewController {
8181

8282
// MARK: - Actions
8383

84-
func updateTweetView() {
84+
@objc func updateTweetView() {
8585
if let tweet = tweet {
8686
configureTweetView(with: tweet)
8787
}

DemoApp/DemoApp/Extensions/ViewExtensions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111

1212
extension UIViewController {
13-
func addVisualConstraints(format: String, views: [String: AnyObject], options: NSLayoutFormatOptions = [], metrics: [String : AnyObject]? = nil) {
13+
func addVisualConstraints(format: String, views: [String: AnyObject], options: NSLayoutConstraint.FormatOptions = [], metrics: [String : AnyObject]? = nil) {
1414
let constraints = NSLayoutConstraint.constraints(withVisualFormat: format, options: options, metrics: metrics, views: views)
1515
constraints.forEach { $0.isActive = true }
1616
}

DemoApp/DemoApp/Navigation/HomeViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class HomeViewController: DemoCollectionViewController {
4343

4444
// MARK: - Actions
4545

46-
func didTapProfile() {
46+
@objc func didTapProfile() {
4747
delegate?.homeViewControllerDidTapProfileButton(viewController: self)
4848
}
4949
}

DemoApp/DemoApp/Navigation/RootAnimationController.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ struct RootAnimationController {
1717
func transition(using transitionContext: RootTransitionContext) {
1818
let toViewController = transitionContext.toViewController
1919

20-
transitionContext.contentViewController.addChildViewController(toViewController)
20+
transitionContext.contentViewController.addChild(toViewController)
2121
toViewController.view.frame = transitionContext.contentViewController.view.bounds
2222
transitionContext.contentViewController.view.addSubview(toViewController.view)
23-
transitionContext.fromViewController?.willMove(toParentViewController: nil)
24-
transitionContext.toViewController.willMove(toParentViewController: transitionContext.contentViewController)
23+
transitionContext.fromViewController?.willMove(toParent: nil)
24+
transitionContext.toViewController.willMove(toParent: transitionContext.contentViewController)
2525

2626
animateTransition(using: transitionContext)
2727
}
@@ -41,7 +41,7 @@ struct RootAnimationController {
4141

4242
private func handleAnimationCompletion(using transitionContext: RootTransitionContext?) {
4343
transitionContext?.fromViewController?.view.removeFromSuperview()
44-
transitionContext?.fromViewController?.removeFromParentViewController()
44+
transitionContext?.fromViewController?.removeFromParent()
4545
if let constraints = transitionContext?.fromViewController?.view.constraints {
4646
transitionContext?.fromViewController?.view.removeConstraints(constraints)
4747
}

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
**How to build and use your customized TwitterKit pod**
2+
1. Open the DemoApp project and there is a sub project TwitterKit.
3+
2. Select schema: TwitterKit ==> Generic iOS Device, `Clean`, `Run` and you get a TwitterKit.framework with architecture: armv7, arm64
4+
3. Select schema: TwitterKit ==> any iOS Simulator, `Clean`, `Run` and you get a TwitterKit.framework with architecture: x86_64
5+
4. Use `lipo` to merge above two framework into one, which include architecture: armv7, arm64, x84_64
6+
```
7+
lipo -create -output TwitterKit <Framework built in step 2>/TwitterKit <Framework built in step 3>/TwitterKit
8+
```
9+
Check the new TwitterKit is correct.
10+
```
11+
lipo -archs TwitterKit
12+
```
13+
Will return `x86_64 armv7 arm64 `
14+
15+
5. Replace the `TwitterKit` in framework created in step 2 with the merged one.
16+
6. Create a folder `iOS`, move the framework folder in step 5 inside, zip the `iOS` folder and you get TwitterKit pod zip file.
17+
7. Upload the zip file somewhere and get a [URL](https://swarm-dev.s3.amazonaws.com/pods/twitterkit/ios/5.0.0/TwitterKit.zip) points to it.
18+
8. Change your [podspec file](https://raw.githubusercontent.com/touren/twitter-kit-ios/Swift5/TwitterKit/TwitterKit.podspec) as: s.source = { :http => "<URL created in step 7>" }
19+
9. Change your Podfile as: `pod "TwitterKit"` ==> `pod "TwitterKit", :podspec => "<URL point to the podspec created in step 8>"`
20+
21+
----
22+
123
**Twitter will be discontinuing support for Twitter Kit on October 31, 2018. [Read the blog post here](https://blog.twitter.com/developer/en_us/topics/tools/2018/discontinuing-support-for-twitter-kit-sdk.html).**
224
325
# Twitter Kit for iOS

TwitterKit/TwitterKit.xcodeproj/project.pbxproj

+7-2
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@
498498
AAF0C9ED2011998F0057F438 /* TwitterShareExtensionUI.h in Headers */ = {isa = PBXBuildFile; fileRef = AAF0C9EC2011998F0057F438 /* TwitterShareExtensionUI.h */; };
499499
AAF0C9F120119C0A0057F438 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AAF0C9EE20119BB40057F438 /* CoreLocation.framework */; };
500500
AAF0C9F220119C2C0057F438 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AAF0C9F020119BED0057F438 /* MapKit.framework */; };
501+
ACB17A0F2335DC330078FDF3 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ACB17A0C2335DC320078FDF3 /* WebKit.framework */; };
501502
BF318EB21ADF320A0082353A /* TWTRDateFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = 9D0AE5A71AC7359D00884B45 /* TWTRDateFormatter.h */; settings = {ATTRIBUTES = (Private, ); }; };
502503
BF318F031AE03B400082353A /* TWTRComposer.h in Headers */ = {isa = PBXBuildFile; fileRef = F5154B8119D4E6130054DECF /* TWTRComposer.h */; settings = {ATTRIBUTES = (Public, ); }; };
503504
BF318F041AE03B4E0082353A /* TWTRTweetView.h in Headers */ = {isa = PBXBuildFile; fileRef = 376CFC20194A7F7F00E982FB /* TWTRTweetView.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -1223,6 +1224,7 @@
12231224
AAF0C9EC2011998F0057F438 /* TwitterShareExtensionUI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TwitterShareExtensionUI.h; sourceTree = "<group>"; };
12241225
AAF0C9EE20119BB40057F438 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
12251226
AAF0C9F020119BED0057F438 /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; };
1227+
ACB17A0C2335DC320078FDF3 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.4.sdk/System/Library/Frameworks/WebKit.framework; sourceTree = DEVELOPER_DIR; };
12261228
BF45C7DC1A1AAE24009C58BE /* TWTRAutoLayoutDebugging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TWTRAutoLayoutDebugging.h; sourceTree = "<group>"; };
12271229
BF45C7DD1A1AAE24009C58BE /* TWTRAutoLayoutDebugging.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TWTRAutoLayoutDebugging.m; sourceTree = "<group>"; };
12281230
BF8EF2DE1AFD4F65008B4829 /* TWTRSessionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TWTRSessionTests.m; sourceTree = "<group>"; };
@@ -1382,6 +1384,7 @@
13821384
isa = PBXFrameworksBuildPhase;
13831385
buildActionMask = 2147483647;
13841386
files = (
1387+
ACB17A0F2335DC330078FDF3 /* WebKit.framework in Frameworks */,
13851388
AA3E099220119CC000792255 /* MobileCoreServices.framework in Frameworks */,
13861389
AAF0C9F220119C2C0057F438 /* MapKit.framework in Frameworks */,
13871390
AAF0C9F120119C0A0057F438 /* CoreLocation.framework in Frameworks */,
@@ -1408,6 +1411,7 @@
14081411
208ACAB41FB2800900008F42 /* Frameworks */ = {
14091412
isa = PBXGroup;
14101413
children = (
1414+
ACB17A0C2335DC320078FDF3 /* WebKit.framework */,
14111415
AA3E099B20125EC600792255 /* MapKit.framework */,
14121416
AA3E099120119CA500792255 /* MobileCoreServices.framework */,
14131417
AAF0C9F020119BED0057F438 /* MapKit.framework */,
@@ -2978,6 +2982,7 @@
29782982
developmentRegion = English;
29792983
hasScannedForEncodings = 0;
29802984
knownRegions = (
2985+
English,
29812986
en,
29822987
ko,
29832988
ja,
@@ -3454,7 +3459,7 @@
34543459
SDKROOT = iphoneos;
34553460
SWIFT_OBJC_BRIDGING_HEADER = "TwitterKitTests/TwitterKit Tests-Bridging-Header.h";
34563461
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
3457-
SWIFT_VERSION = 3.0;
3462+
SWIFT_VERSION = 5.0;
34583463
WRAPPER_EXTENSION = xctest;
34593464
};
34603465
name = Debug;
@@ -3473,7 +3478,7 @@
34733478
SDKROOT = iphoneos;
34743479
SWIFT_OBJC_BRIDGING_HEADER = "TwitterKitTests/TwitterKit Tests-Bridging-Header.h";
34753480
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
3476-
SWIFT_VERSION = 3.0;
3481+
SWIFT_VERSION = 5.0;
34773482
WRAPPER_EXTENSION = xctest;
34783483
};
34793484
name = Release;

TwitterKit/TwitterKit/Social/Identity/TWTRWebViewController.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
*/
2121

2222
#import <UIKit/UIKit.h>
23+
#import <WebKit/WebKit.h>
2324

2425
@class TWTRWebViewController;
2526

2627
typedef BOOL (^TWTRWebViewControllerShouldLoadCompletion)(UIViewController *controller, NSURLRequest *request, UIWebViewNavigationType navigationType);
2728
typedef void (^TWTRWebViewControllerCancelCompletion)(TWTRWebViewController *webViewController);
2829
typedef void (^TWTRWebViewControllerHandleError)(NSError *error);
2930

30-
@interface TWTRWebViewController : UIViewController
31+
@interface TWTRWebViewController : UIViewController <WKNavigationDelegate>
3132

3233
@property (nonatomic, strong) NSURLRequest *request;
3334
@property (nonatomic, copy) TWTRWebViewControllerShouldLoadCompletion shouldStartLoadWithRequest;

TwitterKit/TwitterKit/Social/Identity/TWTRWebViewController.m

+57-13
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,41 @@
1818
#import "TWTRWebViewController.h"
1919
#import <TwitterCore/TWTRAuthenticationConstants.h>
2020

21-
@interface TWTRWebViewController () <UIWebViewDelegate>
21+
@interface TWTRWebViewController () <WKNavigationDelegate>
2222

23-
@property (nonatomic, strong) UIWebView *webView;
23+
@property (nonatomic, strong) WKWebView *webView;
2424
@property (nonatomic, assign) BOOL showCancelButton;
2525
@property (nonatomic, copy) TWTRWebViewControllerCancelCompletion cancelCompletion;
2626

2727
@end
2828

2929
@implementation TWTRWebViewController
3030

31+
// Conversion from UIWebViewNavigationType to WKNavigationType
32+
+ (UIWebViewNavigationType)_enumHelperForNavigationType:(WKNavigationType)wkNavigationType {
33+
switch (wkNavigationType) {
34+
case WKNavigationTypeLinkActivated:
35+
return UIWebViewNavigationTypeLinkClicked;
36+
break;
37+
case WKNavigationTypeFormSubmitted:
38+
return UIWebViewNavigationTypeFormSubmitted;
39+
break;
40+
case WKNavigationTypeBackForward:
41+
return UIWebViewNavigationTypeBackForward;
42+
break;
43+
case WKNavigationTypeReload:
44+
return UIWebViewNavigationTypeReload;
45+
break;
46+
case WKNavigationTypeFormResubmitted:
47+
return UIWebViewNavigationTypeFormResubmitted;
48+
break;
49+
case WKNavigationTypeOther:
50+
default:
51+
return UIWebViewNavigationTypeOther;
52+
break;
53+
}
54+
}
55+
3156
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
3257
{
3358
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
@@ -65,30 +90,32 @@ - (void)load
6590

6691
- (void)loadView
6792
{
68-
[self setWebView:[[UIWebView alloc] init]];
69-
[[self webView] setScalesPageToFit:YES];
70-
[[self webView] setDelegate:self];
93+
[self initWebView];
7194
[self setView:[self webView]];
7295
}
7396

74-
#pragma mark - UIWebview delegate
97+
#pragma mark - WKWebview delegate
7598

76-
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
77-
{
99+
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
100+
NSURLRequest* request = navigationAction.request;
78101
if (![self whitelistedDomain:request]) {
79102
// Open in Safari if request is not whitelisted
80103
NSLog(@"Opening link in Safari browser, as the host is not whitelisted: %@", request.URL);
81104
[[UIApplication sharedApplication] openURL:request.URL];
82-
return NO;
105+
decisionHandler(WKNavigationActionPolicyCancel);
106+
return;
83107
}
108+
WKNavigationActionPolicy decision = WKNavigationActionPolicyAllow;
84109
if ([self shouldStartLoadWithRequest]) {
85-
return [self shouldStartLoadWithRequest](self, request, navigationType);
110+
if (![self shouldStartLoadWithRequest](self, request, [TWTRWebViewController _enumHelperForNavigationType:navigationAction.navigationType])) {
111+
decision = WKNavigationActionPolicyCancel;
112+
};
86113
}
87-
return YES;
114+
115+
decisionHandler(decision);
88116
}
89117

90-
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
91-
{
118+
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
92119
if (self.errorHandler) {
93120
self.errorHandler(error);
94121
self.errorHandler = nil;
@@ -120,4 +147,21 @@ - (void)enableCancelButtonWithCancelCompletion:(TWTRWebViewControllerCancelCompl
120147
[self setCancelCompletion:cancelCompletion];
121148
}
122149

150+
- (void)initWebView {
151+
// From: https://stackoverflow.com/questions/26295277/wkwebview-equivalent-for-uiwebviews-scalespagetofit
152+
NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
153+
154+
WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
155+
WKUserContentController *wkUController = [[WKUserContentController alloc] init];
156+
[wkUController addUserScript:wkUScript];
157+
158+
WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
159+
wkWebConfig.userContentController = wkUController;
160+
161+
WKWebView* wkWebV = [[WKWebView alloc] initWithFrame:self.view.frame configuration:wkWebConfig];
162+
163+
[self setWebView:wkWebV];
164+
[[self webView] setNavigationDelegate:self];
165+
166+
}
123167
@end

0 commit comments

Comments
 (0)