Giter VIP home page Giter VIP logo

towebviewcontroller's Introduction

With the announcement of iOS 12, UIWebView is now officially deprecated. As of iOS 13, Apple have started rejecting apps that implement UIWebView, rendering this library completely defunct.

This library will be left up for developers who may still need to support iOS 7, but no new features will be added, nor will support be provided. Stay tuned. Plans for a WKWebView version are in the making. :D


TOWebViewController

An Inline Web Browser for iOS Apps

TOWebViewController

CI Status Version Carthage compatible GitHub license Platform Beerpay PayPal Twitch

TOWebViewController is an open-source UIViewController subclass designed to let apps quickly present web page content to its users, without needing to kick them over to Safari. TOWebViewController has been designed from the ground up to be easily integrated into existing projects, to take advantage of the latest features of iOS, and to optionally be backwards compatible with (significantly) earlier versions of iOS.

Features

  • Powered by UIWebView, backwards compatible down to iOS 5.
  • Full navigation buttons set, including back, forward, refresh and an optional share/action button.
  • Detects whether being pushed modally, or via a navigation controller and adjusts the UI accordingly.
  • A page load progress bar (using ninjinkun's amazing algorithm).
  • Plays a smooth, elegant rotation animation if/when the user rotates the device.
  • Icons are procedurally generated by CoreGraphics (ie, no unnecessary image assets at all!).
  • Compatible with iOS 8 size classes, including split-screen on iPad Air 2, iPad mini 4 and iPad Pro.
  • 1Password automatic password input extension support.

Example

TOWebViewController is smart enough to be able to tell when it's being presented as a modal popup, and when it's being pushed onto a UINavigationController and to change its button layout accordingly.

Presenting as a Modal Dialog

When presenting as a modal popup, it is still necessary to create a parent UINavigationController in order for the buttons to display properly:

TOWebViewController *webViewController = [[TOWebViewController alloc] initWithURL:[NSURL URLWithString:@"http://www.apple.com/"]];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:webViewController];
[self presentViewController:navigationController animated:YES completion:nil];

Pushing onto a UINavigationController

TOWebViewController *webViewController = [[TOWebViewController alloc] initWithURL:[NSURL URLWithString:@"http://www.apple.com/"]];
[self.navigationController pushViewController:webViewController animated:YES];

System Requirements

iOS 5.0 or above

Installation

As a CocoaPods Dependency

Add the following to your Podfile:

pod 'TOWebViewController'

As a Carthage Dependency

Add the following to your Cartfile:

github "https://github.com/TimOliver/TOWebViewController"

Manual Installation

Download this project from GitHub, move the subfolder named 'TOWebViewController' over to your project folder, and drag it into your Xcode project.

After that, you'll need to link the following system frameworks to your project:

  • QuartzCore.framework
  • CoreGraphics.framework
  • MessageUI.framework
  • Twitter.framework

Why no WKWebView adoption?

This library was originally built around iOS 5, with the explicit goal of supporting as many versions of iOS as possible. While there were some experiments in trying to drop WKWebView into this controller as an option for devices running iOS 8 and above, its API is so inherantly different to UIWebView that it would be very challenging to properly support switching between the two. As a result, the best option would be to write a new web view controller from scratch, designed around WKWebView.

TOWebViewController will not be adopting WKWebView at any point in the future. If you would like an alternative view controller that does, please give DZNWebViewController a try!

What about SFSafariViewController?

Starting from iOS 9, Apple now provides a built-in web view controller of similar functionality named SFSafariViewController. If your app is only targeting iOS 9, and it completely fills your requirements, then it is absolutely recommended that you adopt SFSafariViewController instead of TOWebViewController.

That being said, if you are still targeting lower iOS versions, or require more customisability than SFSafariViewController provides, then TOWebViewController can still serve as a viable alternative.

Credits

TOWebViewController was originally created by Tim Oliver as a component for iComics, a comic reader app for iOS.

Thanks also goes to TOWebViewController's growing list of contributors!

iPad Pro and iPhone X device mockups by Pixeden. iPod touch mockup by Tim Oliver.

License

TOWebViewController is licensed under the MIT License. For more information, please see the LICENSE file. analytics

towebviewcontroller's People

Contributors

alvis-li avatar buh avatar cfiorini avatar cupnoodle avatar dkhamsing avatar fulldecent avatar hyperspacemark avatar jeremypiednoel avatar kevin-lyn avatar masawo avatar mclkyo avatar melsam avatar metasmile avatar musclemikiya avatar mvasilak avatar nickplee avatar plu avatar readmecritic avatar sapzildj avatar sarstw avatar sebastianbaar avatar sergii-frost avatar stephpaquet avatar timoliver avatar uzegonemad avatar ykws avatar yoyoworms avatar zachchen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

towebviewcontroller's Issues

In some webs, NetworkActivityIndicator is always Visible

In some webs, NetworkActivityIndicator is always Visible.

There seems to be something wrong when checking whether a url is redirected which leads to not call finishLoadProgress finally.

    BOOL isNotRedirect = self.url && [self.url isEqual:self.webView.request.mainDocumentURL];

Best way to implement interstitialPresentationPolicy

Hi,

Is there a way to implement interstitialPresentationPolicy = ADInterstitialPresentationPolicyAutomatic; for iAd?

Is it ok to do this:

TOWebViewController *webViewController = [[TOWebViewController alloc] initWithURL:@"url"];

        webViewController.interstitialPresentationPolicy = ADInterstitialPresentationPolicyAutomatic;

        [self presentViewController:[[UINavigationController alloc] initWithRootViewController:webViewController] animated:YES completion:^{
            NSLog(@"presentViewController");
        }];

Because this way it only happens once, and the other times I try to open other links it won't display the iAd Interstitial. I am not sure if this is the development issue that Interstitial is not ready or is there a better place to set the interstitialPresentationPolicy.

Thanks

part of screen is black while initialize and load request

I found this problem. when i run demo app on iOS simulator,it can load request at first time appear.
Network environment: 100% lost,make sure it waiting until time out.
Result: contentSize of UIWebView not equal CGSizeZero, I swipe to bottom, found bottom part of screen is display black .
thank you.

When I learned your WebView before the call to the getview method in the push, will lead to premature call loadview and viewwillload, self.navigationController at this time of nil, so it will bring a lot of dependencies in navigationController whether the empty allocation failure

When I learned your WebView before the call to the getview method in the push, will lead to premature call loadview and viewwillload, self.navigationController at this time of nil, so it will bring a lot of dependencies in navigationController whether the empty allocation failure

iOS 9 App transport security

Hi;

I could not get it work with iOS 9. It was working fine when I was compiling with base iOS 8. But the new security changes for iOS 9 has broken my current implementation.

When I tried to open a page it gives the error below.

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

I've added the property below to my plist file it also didn't help.

    <key>NSAllowArbitraryLoads</key>
    <true/>

Do you have any idea about this problem?

Question on same-origin policy (SOP) across iframes

Does TOWebViewController's webkit implementation allow access to web preferences so that one can disable SOP across iframes that have different origins? Or is it just a view controller built over the standard iOS Webkit library?

Wrong to add one more TabBar :(

When I was at the top of the TabBarController, there was TabBar. Then I use the following code:

TOWebViewController *webViewController = [[TOWebViewController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kHostURLString,@"jr_abouts.html"]]];
webViewController.title = @"产品介绍";
webViewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:webViewController animated:YES];

Pop hand gesture to return to half, and then I cancel the pop gesture, stay in the TOWebViewController, it occurs Bug.
My TabBarController is wrong to add one more TabBar.

Update podspec file

Hi, I noticed the podspec file is not the latest version. The master branch has fixed some bugs, please update the podspec file, thank you very much.

Navigation toolbar not hiding properly

I'm using this (awesome) viewcontroller but I need to hide the toolbar in some cases. Doing something like this will hide the buttons but the toolbar stays there.

TOWebViewController *controller = [[TOWebViewController alloc] initWithURLString:webpageUrl];
controller.navigationButtonsHidden = YES;
[[self navigationController] pushViewController:controller animated:YES];

I dived in the code and saw that the navigationButtonsHidden setter tries to hide the toolbar but it makes it before viewwillappear so when viewwillappear gets called, the toolbar will show again (empty).

Doing it like this (dispathing it in the next update cycle) works but it's not ideal.

TOWebViewController *controller = [[TOWebViewController alloc] initWithURLString:webpageUrl];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    controller.navigationButtonsHidden = YES;
});
[[self navigationController] pushViewController:controller animated:YES];

Nav bar is always visible.

I've been pushing the TOWebViewController on a UINavigationController and the hideNavBarOnClose is always NO. When I change the stack of view controllers (wanting to keep the web view in memory - but not in view) the toolbar at the bottom remains visible gray and no buttons.

Can you think of a way that I'm mis-using this and can get this control to hide the navbar at the bottom when the viewWillDisappear runs?

iOS 8 Support

_NDA Disclaimer: In case you hadn't heard, Apple is not enforcing a Non-Disclosure Agreement on code changes and new APIs in the iOS beta releases this time around. While we're not allowed to post screenshots of iOS 8, or release any review-style articles, we ARE allowed to discuss these sorts of code changes publicly._

I'm going to post this issue and leave it open for the time being, since I think I can guarantee that other developers might be wondering about this.

If you haven't watched the WWDC session videos on Cocoa Touch and UIKit yet, you might be surprised to learn that Apple has decided to completely overhaul the iOS paradigm when it comes to the UI handling device rotations. No longer does the code recognise the concept of 'portrait' or 'landscape' orientation modes, but they now simply treat these events as the UI's boundary sizes changing.

Because of this new design paradigm in iOS 8, a LOT of the internal animation code behind UIView and UIViewController appears to have been modified, so much so that a lot of the assumptions I had made when developing TOWebViewController for iOS 6 and iOS 7 no longer directly apply.

After testing the last build of TOWebViewController in one of my own apps running iOS 8, I discovered that the rotation code was causing the app to crash. I also noticed that the 'snapshot' image displayed when the device is rotated also stopped displaying. I spent a little time this evening and was able to fix the crash, and get the majority of the snapshot animations working properly again on iOS 8, although they sometimes don't match up properly. Those fixes are now pushed to this library, but not submitted to CocoaPods yet.

In any case, given past iOS beta releases, it's pretty likely that iOS 8 will undergo a pretty heavy set of revisions before it is finally released to the public, so it's probably not worth trying to perfect the class for iOS 8 just yet. As such, I'm going to hold off from any more iOS 8 'fixes' in the codebase until iOS 8 goes gold.

Either way, if you're using TOWebViewController in one of your apps, and are starting to test for iOS 8, this is something to be aware of. :)

Happy coding!

Landscape mode

Hi, how use your view controller in landscape mode in a only portrait app?

load automatically fin view controller

Hi... I am having a little problem as i am new to this. I simply want to hardcode the url in a view controller and when i access the view controller it loads the url automatically. I don't want to have a page before with a tableview that when i click the page loads.

How do i do this?

there is not way to use webViewDidFinishLoad

i want to add a JSContext to webview in webViewDidFinishLoad function,but there is no way to implementation this method,Can you add a block like shouldStartLoadRequestHandler?thank you

Russian and ukranian localizations are located at wrong path

Hi!

Directories for ru.lproj and uk.lproj are located inside of en.lproj directory, so these localizations don't work.
I would also suggest to use initWithBarButtonSystemItem:UIBarButtonSystemItemDone for Done button. It will use system localization for 'Done' text, so no localization is needed on iOS 6+, while UI looks the same.

TOWebViewControllerDelegate?

Hi, I wish you can design TOWebViewControllerDelegate, so we can hook on webView: shouldStartLoadWithRequest:navigationType method to implement JS-to-cocoa bridge features ourselves.

Landscape support for portrait app

Hi,

My app is only working in one orientation (portrait). This is how the app is designed, however when the url is opened by TOWebViewController I don't mind user rotate the device to landscape especially when the webpage contains video.

At the moment it only displays the portrait orientation (even when the video is playing). Is there a way to set the shouldRotate for TOWebViewController *webViewController before it opens?

Thanks.

Please update Pod.

The current Pod release doesn't match the repo.
Please update the Pod. Thanks.

Error when using tab bar controller

Hi When i use a standard tab bar the towebviecontrooler loads fine... However if i use a storyboard tabbar controller i get the following error.

Can you assist?

screen shot 2015-10-02 at 10 09 49 pm

Change webView public scope to work with Javascript injection

Ususally, we want to inject javascript to webview for some native/js invokation. Like

[WebViewJavascriptBridge bridgeForWebView:self.webView webViewDelegate:self handler:^(id data, WVJBResponseCallback responseCallback) {
        NSLog(@"ObjC received message from JS: %@", data);
        responseCallback(@"Response for message from ObjC");
    }];

Is that okay to move the

@property (nonatomic,strong)    UIWebView *webView;

to .h ?

How to use modalCompletionHandler

Hi Tim,

I found out modalCompletionHandler in doneButtonTapped. Is there any way to use this when I use presentViewController to find out if the TOWebViewController dismissed?

Thakns

Toolbar not hide(Cocoapods version 2.0.14)

TOWebViewController *webViewController = [[TOWebViewController alloc] initWithURLString:[@"google.com" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
webViewController.navigationButtonsHidden = YES;
[[UIViewController currentViewController].navigationController pushViewController:webViewController animated:YES];

The toolbar will not hide in Cocoapods version 2.0.14.
Download the ZIP and add the files into your project. The github version is OK.

Thoughts on allowing NSURLRequest to be modified?

I have a scenario where I need to pass a HTTP header with a request. (It's an oauth bearer token)

Normally, I would make a mutable request and then use the built in methods for adding header fields, but TOWebViewController doesn't seem to expose the request in a manner that I can modify.

I'm posting this more for discussion than anything. What are your thoughts on adding methods to enable exposing the request?

Toolbar Not Hiding

I've been getting a bug sporadically where after poping the web view controller the toolbar is still there.

TabBar error

if the web view add interactivePopGestureRecognizer , when view back with popGesture again , the property navigationButtonsHidden set is the tabbar title is hidden ,but the tabbar is not hidden. how to reslut this . the error image like this .
bug gif Image
this is test demo, the bug.gif is the error gif image , you can look it

Address Bar

Add an address bar for free browsing. Great library, Thanks!

Change tab bar tintColor

Am I making a mistake or is it impossible in iOS 7 to change the tintColor of the tab bar buttons?
Would perhaps require to use a real UITabBar?

How to avoid navbar background/text overrides?

Hello, I recently tried to plug your control in place of the SVWebViewController. I like the approach this control is taking but I ran into a couple issues I'm not sure how to work around.

  • Issue 1:

    I'm pushing the control onto a UINavigationController where I'd like the background and text colors to remain the same (as were previously there). It seems like this control is plugging it's own style onto it. Can this be done?

  • Issue 2

    I have a 'hamburger icon' menu for the left navigation bar when it's the first view controller on the stack. How can I get this control to play nice with this scenario? I'd like there to not be a disabled (left/back arrow) and instead display my custom Hamburger Menu icon.

Communications error

When I tap action button, my app crash. It also happens in example app.

My ios version is 8.1.2, and my xcode version is 6.1.1.

Test my app on iphone 5.

screenshot 2014-12-16 10 21 56

Typo in readme

Hey there,

Thanks for the lib. Looks great and excited to use it.
Want to let you know about a minor typo.

TOWebViewController *webViewController = [[TOWebViewController alloc] initWithURL:[NSURL URLWithString:@"http://www.apple.com/"];

should be

TOWebViewController *webViewController = [[TOWebViewController alloc] initWithURL:[NSURL URLWithString:@"http://www.apple.com/"]];

Conflict with any localization in the main app.

When using TOWebViewController via CocoaPods, the lproj directories are copied to the root of the main bundle. This causes two issues:

  1. They conflict with any localization in the main app.
  2. The App Store detects these localized bundles and assumes the app is fully localized into all 6 languages TOWebViewController supports (de, en, es, ja, ko, pl, ..). We only support German.

This is a real problem. I think best idea for pods is to use ressource_bundles instead of resources. http://guides.cocoapods.org/syntax/podspec.html#resource_bundles

ios 7 toolbar

Hi
in ios7 iphone the bottom toolbar appears at the top. both in modal view and navigation view.
also in your example...

iOS7 deprecations

Hi Tim,
Getting a lot of warnings about depracations on iOS7.1 and Xcode 5.1

Planning on upgrading this or are these a necessary evil to keep backwards compatibility?

Create subspecs/pod for Chrome/Safari UIActivities

These would be super useful to have as subspecs (or as a separate Pod entirely that TOWebViewController depends on) for those who just need the Chrome/Safari UIActivitys without the custom web view controller. They seem to be some pretty solid implementations with some great icons as well. Good work!

navigationController.navigationBar becomes visible after leaving the TOWevViewController

Hello there!
Thanx for the amazing tool you've created
Please take a look at a small problem I've confronted

- (void)viewDidLoad
{
    [super viewDidLoad];

    if (self.navigationController) {
        self.hideToolbarOnClose = self.navigationController.toolbarHidden;
        self.hideNavBarOnClose  = self.navigationBar.hidden;
    }
...

In some rare cases it may occur, that viewDidLoad gets called before the view controller gets inserted in the navigation controller's stack. This will cause the toolbar to appear after the view disappears

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    if (self.beingPresentedModally == NO) {
        [self.navigationController setToolbarHidden:self.hideToolbarOnClose animated:animated];
        [self.navigationController setNavigationBarHidden:self.hideNavBarOnClose animated:animated];
    }
}

Could you please move your code

    if (self.navigationController) {
        self.hideToolbarOnClose = self.navigationController.toolbarHidden;
        self.hideNavBarOnClose  = self.navigationBar.hidden;
    }

to the viewWillAppear: method ?

Thanx in advance

WrongTitle when come back from other View Controller

I push a view controller from TOWebViewController, and then pop to TOWebViewController, the title becomes "Loading...", actually, the web view is completed!

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    //Show placehodler title until we work out the new one
    [self showPlaceholderTitle]; //<===== wrong here 
    ...
}

- (void)showPlaceholderTitle
{
    //set the title to the URL until we load the page properly
    if (self.url && self.showPageTitles && self.showUrlWhileLoading) {
        NSString *url = [_url absoluteString];
        url = [url stringByReplacingOccurrencesOfString:@"http://" withString:@""];
        url = [url stringByReplacingOccurrencesOfString:@"https://" withString:@""];
        self.title = url;
    }
    else if (self.showPageTitles) {

    //===== wrong here ======
    //you should check the current page real status
        self.title = NSLocalizedStringFromTable(@"Loading...", @"TOWebViewControllerLocalizable", @"Loading...");
    //===== wrong here ======
    }
}

Suppress iOS8 detection warning when using cocoapods

When using the cocoapod, I noticed that there are compiler warnings due to some detection in TOWebViewController.m for the new iOS8 device rotation system. The macro checks if UIViewController responds to the new selector viewWillTransitionToSize:withTransitionCoordinator:, which raises the warning

"TOWebViewController.m:1519:9: Undeclared selector 'viewWillTransitionToSize:withTransitionCoordinator:'" where the NEW_ROTATIONS identifier is used.

I don't see this warning when I download the source and use the demo project. I also don't see it when using Xcode6-beta, so I'm wondering if this may be an Xcode5 bug or something else.

To test, create a single view app, pod install TOWebViewController as usual, then import TOWebViewController.h in your view controller implementation file. Build with Xcode5 targeting 7.1 and you should see the warnings.

For what it's worth, maybe a better option is replacing the macro with:

#define NEW_ROTATIONS   ([[UIViewController class] instancesRespondToSelector:NSSelectorFromString(@"viewWillTransitionToSize:withTransitionCoordinator:")])

which creates the selector at runtime instead instead of compile time, which suppresses the warning(s).

Status Bar color

If in your app you have a white status bar when call TOWebViewController status bar is not visible.

In my case i put in TOWebViewController.m viewDidLoad add

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];

and in doneButtonTapped

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

But maybe is better create a system that check the previous status bar colo and reset it when controller is dismissed

Preserve Application Buttons (e.g. Left Menu hamburger button)

Hi,
I have found your pod quite easy to use, but I am facing some issues when it comes to using it within app which is based on Left Menu navigation (e.g. https://github.com/gotosleep/JASidePanels )

The case is that I want to use TOWebViewcontroller wrapped in UINavigationController and still show Menu hamburger button as the leftBarButtonItem so that user could open menu still.

I have tried adding my hamburger button to the applicationBarButtonItems but then it goes to the toolbar.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.