GithubHelp home page GithubHelp logo

zxfmpy / routable-ios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from clayallsopp/routable-ios

0.0 2.0 0.0 73 KB

Routable, an in-app native URL router, for iOS

License: MIT License

Ruby 1.13% Objective-C 98.87%

routable-ios's Introduction

Routable Build Status FOSSA Status

Routable is an in-app native URL router, for iOS. Also available for Android.

Usage

Set up your app's router and URLs (usually done in application:didFinishLaunchingWithOptions:):

[[Routable sharedRouter] map:@"users/:id" toController:[UserController class]];
// Requires an instance of UINavigationController to open UIViewControllers
[[Routable sharedRouter] setNavigationController:aNavigationController];

Implement initWithRouterParams: in your UIViewController subclass:

@implementation UserController

// params will be non-nil
- (id)initWithRouterParams:(NSDictionary *)params {
  if ((self = [self initWithNibName:nil bundle:nil])) {
    self.userId = [params objectForKey:@"id"];
  }
  return self;
}

Then, anywhere else in your app, open a URL:

NSString *aUrl = @"users/4";
[[Routable sharedRouter] open:aUrl];

If you wish to do custom allocation of a controller, you can use +allocWithRouterParams:

[[Routable sharedRouter] map:@"users/:id" toController:[StoryboardController class]];

@implementation StoryboardController

+ (id)allocWithRouterParams:(NSDictionary *)params {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
    StoryboardController *instance = [storyboard instantiateViewControllerWithIdentifier:@"sbController"];
    instance.userId = [params objectForKey:@"id"];

    return instance;
}

Set ignoresExceptions to YES to NOT throw exceptions (suggested for a Release/Distribution version)

[[Routable sharedRouter] setIgnoresExceptions:YES];

Installation

pod 'Routable', '~> 0.1.1'
#import <Routable/Routable.h>

If you're not able to use CocoaPods, please install Routable as a git submodule and add the files to your Xcode project.

Features

Anonymous Callbacks

You can invoke anonymous callbacks with Routable:

[[Routable sharedRouter] map:@"invalidate/:id" toCallback:^(NSDictionary *params) {
  [Cache invalidate: [params objectForKey:@"id"]]];
}];

[[Routable sharedRouter] open:@"invalidate/5h1b2bs"];

Presentation Options

You can configure if and how a UIViewController is presented modally with UPRouterOptions:

UPRouterOptions *options = [[UPRouterOptions modal] withPresentationStyle: UIModalPresentationFormSheet];
[self.router map:@"info" toController:[InfoController class]
                          withOptions:options];

UPRouterOptions has the following DSL setters:

  • modal
  • withPresentationStyle:
  • withTransitionStyle:
  • forDefaultParams:

Open External URLs

Sometimes you want to open a URL outside of your app, like a YouTube URL or open a web URL in the browser. You can use Routable to do that:

[[Routable sharedRouter] openExternal:@"http://www.youtube.com/watch?v=oHg5SJYRHA0"];

Multiple Routers

If you need to use multiple routers, simply create new instances of Router:

UPRouter *adminRouter = [Routable newRouter];
[adminRouter map:@"profile" toController: [AdminProfile class]];

UPRouter *userRouter = [Routable newRouter];
[userRouter map:@"profile" toController: [UserProfile class]];

Contact

Clay Allsopp (http://clayallsopp.com)

License

Routable for iOS is available under the MIT license. See the LICENSE file for more info.

FOSSA Status

routable-ios's People

Contributors

clayallsopp avatar croath avatar northstar avatar angelodipaolo avatar sweetverbs avatar dlackty avatar skyebook avatar fleitz avatar xizhao avatar aelam avatar jercik avatar

Watchers

James Cloos avatar zxfmpy 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.