Instantly share code, notes, and snippets.

Embed
What would you like to do?
A app router designation
#import <Foundation/Foundation.h>
@class RTRouter;
typedef void(^RTRouteCompleteBlock)(void);
@protocol RTRoutable <NSObject>
@optional
+ (BOOL)routerDidRoutePattern:(NSString *)pattern
withParameters:(id)parameters
complete:(RTRouteCompleteBlock)complete;
@end
@protocol RTRouterDelegate <NSObject>
@optional
- (BOOL)router:(RTRouter *)router shouldRoutePattern:(NSString *)pattern withParameter:(id)parameter;
- (void)router:(RTRouter *)router willRoutePattern:(NSString *)pattern withParameter:(id)parameter;
- (void)router:(RTRouter *)router didRoutePattern:(NSString *)pattern withParameter:(id)parameter;
- (void)router:(RTRouter *)router didFailRoutePattern:(NSString *)pattern withParameter:(id)parameter;
@end
@interface RTRouter : NSObject
+ (void)setScheme:(NSString *)scheme;
+ (NSString *)scheme;
+ (void)setDelegate:(id<RTRouterDelegate>)delegate;
+ (id<RTRouterDelegate>)delegate;
+ (void)registerURLPattern:(NSString *)pattern withRoutable:(Class<RTRoutable>)routable;
+ (void)registerURLPattern:(NSString *)pattern withBlock:(BOOL(^)(id parameters, RTRouteCompleteBlock complete))handler;
+ (void)registerURLPattern:(NSString *)pattern forScheme:(NSString *)scheme withRoutable:(Class<RTRoutable>)routable;
+ (void)registerURLPattern:(NSString *)pattern forScheme:(NSString *)scheme withBlock:(BOOL(^)(id parameters, RTRouteCompleteBlock complete))handler;
+ (BOOL)canOpenURL:(NSURL *)url;
+ (BOOL)openURL:(NSURL *)url;
+ (BOOL)openURL:(NSURL *)url parameter:(id)parameter;
+ (BOOL)openURL:(NSURL *)url parameter:(id)parameter complete:(void(^)())block;
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment