Latest 0.3.0
Homepage https://github.com/jayla25349/WQRoute
License MIT
Platforms ios 7.0
Frameworks Foundation
Authors

CI Status
Version
License
Platform

Example

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

Requirements

This library requires iOS 7.0+ and Xcode 8.0+.

Installation

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

pod "WQRoute"

Then, run the following command:

$ pod install

Usage

Registering a route

@implementation WQLoginVC

+ (void)load {
    ROUTE(@"^/present/loginVC/(\S+)/(\S+)$", presentLoginVC:)
    ROUTE(@"^/user/login/(\S+)/(\S+)$", userLogin:username:password:)
}

//The first parameter must be a WQRouteRequest
+ (void)presentLoginVC:(WQRouteRequest *)request {
    WQLoginVC *vc = [WQLoginVC controller];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [[[[UIApplication sharedApplication] delegate] window].rootViewController presentViewController:nav animated:YES completion:nil];
}

//The first parameter must be a WQRouteRequest
//WQRouter will automatic injection parameters(eg. username and password)
+ (void)userLogin:(WQRouteRequest *)request username:(NSString *)username password:(NSString *)password{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];

    NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:request.queryParameters];
    [parameters setValue:username forKey:@"username"];
    [parameters setValue:password forKey:@"password"];
    [manager GET:@"http://www.baidu.com" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (request.callBack) {
            request.callBack(request, responseObject, nil);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (request.callBack) {
            request.callBack(request, nil, error);
        }
    }];
}

@end

Registering a middleware

@implementation WQAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[WQRouter defaultRouter] registerMiddleware:[WQRouteURLVerifyMiddleware middlewareWithScheme:@"testzzb" host:@"woqugame"]];
    [[WQRouter defaultRouter] registerMiddleware:[WQRouteURLParserMiddleware new]];
    return YES;
}

@end

Calling a route

- (void)test1 {
    NSString *urlString = @"testzzb://woqugame/present/loginVC/admin/123456789/";
    [[WQRouter defaultRouter] routeURLString:urlString data:nil callBack:nil];
}

- (void)test2 {
    [SVProgressHUD show];
    NSString *urlString = @"testzzb://woqugame/user/login/admin/123456789";
    [[WQRouter defaultRouter] routeURLString:urlString data:nil callBack:^(WQRouteRequest * _Nonnull request, id  _Nullable response, NSError * _Nullable error) {
        if (error) {
            [SVProgressHUD showErrorWithStatus:error.localizedDescription];
        } else {
            [SVProgressHUD dismiss];
            NSString *string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Test api service" message:string delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
        }
    }];
}

Author

jayla25349

License

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

Latest podspec

{
    "name": "WQRoute",
    "version": "0.3.0",
    "summary": "A route framework for ios.",
    "description": "WQRoute is a route framework for iOS.",
    "homepage": "https://github.com/jayla25349/WQRoute",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "jayla25349": "[email protected]"
    },
    "source": {
        "git": "https://github.com/jayla25349/WQRoute.git",
        "tag": "0.3.0"
    },
    "platforms": {
        "ios": "7.0"
    },
    "pod_target_xcconfig": {
        "OTHER_LDFLAGS": "-lObjC"
    },
    "source_files": "WQRoute/Classes/**/*",
    "public_header_files": "WQRoute/Classes/**/*.h",
    "frameworks": "Foundation"
}

Pin It on Pinterest

Share This