GithubHelp home page GithubHelp logo

isabella232 / wlxwebviewreloader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wolox/wlxwebviewreloader

0.0 0.0 0.0 193 KB

An extension to WKWebView that reloads the web view when the source changes.

License: MIT License

Ruby 14.28% Objective-C 84.34% HTML 1.38%

wlxwebviewreloader's Introduction

WLXWebViewReloader

Version License Platform

WLXWebViewReloader helps you develop iOS projects that depend on code executed inside a WKWebView. As you might know every time you update a resource file (like a Javascript source file) you need to perform a clean build in order for those changes to get updated into the ipa file. Depending on the size of your project and the amount of resources could take quite a bit of time and doing a clean install every time you update a line of (Javascript) code might upset you.

Using this Pod and the webview-reloader-server you no longer need to do a clean install every time you update your Javascript code. The webview-reloader-server will watch for changes in your source code and it will automatically reload the webview. The server also serves (pound intended) the webview's HTML page for you to be able to edit the source code without needing to re-deploy the app.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

For this Pod to actually work you need to install the webview-reloader-server.

brew install node
npm install -g webview-reloader-server

Installation

WLXWebViewReloader is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "WLXWebViewReloader"

Usage

In your view controller import WLWebViewReloader category

#import <WLXWebViewReloader/WKWebView+WLXWebViewReloader.h>

and here is an example of how to configure the web view

#import "ViewController.h"
#import <WLXWebViewReloader/WKWebView+WLXWebViewReloader.h>

@import WebKit;

@interface ViewController ()<WKNavigationDelegate, WLXWebViewReloaderDelegate>

@property (nonatomic) WKWebView * webView;
@property (nonatomic) WLXWebViewReloader * webViewReloader;

@end

@implementation ViewController

- (void)loadView {
    [super loadView];
    self.webView = [[WKWebView alloc] init];
    self.view = self.webView;
}

- (void)viewDidLoad {
    [super viewDidLoad];

#ifdef DEBUG
    self.webView.reloaderIdentifier = @"MyWebView";
    self.webView.reloaderDelegate = self;
    [self.webView reloadOnFileChange];
#endif

    NSURL * URL = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
    NSURLRequest * request = [NSURLRequest requestWithURL:URL];
    self.webView.navigationDelegate = self;
    [self.webView loadLocalRequest:request];
}

- (void)viewWillAppear:(BOOL)animated {
    [self.webView startListeningToFileChanges];
}

- (void)viewWillDisappear:(BOOL)animated {
    [self.webView stopListeningToFileChanges];
}

#pragma mark - WLXWebViewReloaderDelegate methods

- (void)webViewReloader:(WLXWebViewReloader *)reloader didFailToConnect:(NSError *)error {
    NSLog(@"Error connecting reloader: %@", error);
}

- (void)webViewReloaderDidConnect:(WLXWebViewReloader *)reloader {
    NSLog(@"Reloader connected!");
}

- (void)webViewReloader:(WLXWebViewReloader *)reloader willReloadWebView:(WKWebView *)webView {
    NSLog(@"Web view about to be reloaded");
}

- (void)webViewReloader:(WLXWebViewReloader *)reloader didReloadWebView:(WKWebView *)webView {
    NSLog(@"Web view reloaded!");
}

@end

The reloaderIdentifier of the web view needs to match the listener's name you configured in the webview-reloader-server's configuration file.

Also you need to call loadLocalRequest: instead of loadRequest to be able to load the source code from the web server. If the reloader has not been configured the loadLocalRequest forwards to loadRequest.

About

This project is maintained by Guido Marucci Blas and it was written by Wolox.

Wolox

License

WLXWebViewReloader is available under the MIT license.

Copyright (c) 2014 Guido Marucci Blas <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

wlxwebviewreloader's People

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.