Giter VIP home page Giter VIP logo

fiswebviewpreloader's Introduction

#FISWebViewPreloader FISWebViewPreloader is Cocoapod which helps loading UIWebView objects in the background so they can be presented without delays.


##Installing FISWebViewPreloader You can install FISWebViewPreloader in your project by using CocoaPods:

pod 'FISWebViewPreloader'

##Using FISWebViewPreloader to create pre-loaded UIWebView objects Using FISWebViewPreloader is very easy. We recommend creating a private variable to use FISWebViewPreloader:

@property (strong,nonatomic) FISWebViewPreloader *preloader;

....

self.preloader = [FISWebViewPreloader new];

Any time you need to create a pre-loaded UIWebView object, you can add your URL string to FISWebViewPreloader's dictionary.

[self.preloader setURLString:@"http://www.google.com" forKey:@"Google"];

If you need to scale the web pages to fit a certain frame, you can pass the Width and Length values of your frame:

[self.preloader setURLString:@"http://www.apple.com"
                          forKey:@"Apple"
                      withCGRect:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height)];

##Adding Capacity constraint with scheduling If you are concerned about FISWebViewPreloader to take too much memory, you can define a capacity for the number of UIWebViews to be created and pre-loaded.

self.preloader = [[FISWebViewPreloader alloc] initWithCapacity:5 scheduleType:FIFO];

This will make sure that if more than 5 UIWebViews are added, older UIWebViews will be removed based on your specified ScheduleType (LIFO or FIFO). If you try to access an already-dequeued UIWebView, the requested UIWebView will be re-created on the fly.

Whenever you access a UIWebView object it will automatically be placed at the head of the priorityQueue.


##Accessing your pre-loaded UIWebView objects

There are two ways of accessing the pre-loaded UIWebView objects. You can either retrieve your UIWebView object at the time of their creation:

UIWebView *googleWebView = [self.preloader setURLString:@"http://www.google.com" forKey:@"Google"];

Alternatively, you can use FISWebViewPreloader's webViewForKey: method:

UIWebView *googleWebView = [self.preloader webViewForKey:@"Google"];

You can use the following method to access the key for a given UIWebView:

NSString *myKey = [self.preloader keyForWebView:googleWebView];
//myKey will be @"Google"

##UIWebViewDelegate Protocol:

If your View Controller adheres to the UIWebViewDelegate protocol, then you can use a similar pattern to below to access delegate methods:

-(void)createWebViews
{
    UIWebView *googleWebView = [self.preloader setURLString:@"http://www.google.com" forKey:@"Google"];
    googleWebView.delegate = self;
}

#pragma mark UIWebViewDelegate methods

- (void)webViewDidStartLoad:(UIWebView *)webView {
    NSLog(@"Started loading %@", [self.preloader keyForWebView:webView]);
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    NSLog(@"Finished loading %@", [self.preloader keyForWebView:webView]);
}

##Removing pre-loaded UIWebView objects

You can call the removeWebViewForKey: method to stop the destroy any UIWebView objects that you no longer need:

[self.preloader removeWebViewForKey:@"Google"];

You can also call the reset: method to destroy all key/object pairs in the preloader and the priorityQueue:

[self.preloader reset];

fiswebviewpreloader's People

Contributors

jameslin101 avatar bakyelli avatar jmburges avatar

Watchers

James Cloos avatar  avatar

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.