Custom URL Schemes

Custom URL Schemes

  • Implementing a Custom URL Scheme

    Defining your app's custom URL Scheme is all done in the Info.plist file.

  • Handling Custom URL Calls

    -(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    // handle code here
    }
  • Parsing the Custom URL
    Scheme://host/path?query
    
    -(NSDictionary *) parseQueryString:(NSString *) query{
        
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:6];
        NSArray *pairs = [query componentsSeparatedByString:@"&"];
        
        for(NSString *pair in pairs) {
            NSArray *elements = [pair componentsSeparatedByString:@"="];
            NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            NSString *val = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            
            [dict setObject:val forKey:key];
        } 
        return dict;
    }
  • Testing The Custom URL
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"myAppScheme://test_page/one?token=1234&domain=foo.com"]];

http://www.idev101.com/code/Objective-C/custom_url_schemes.html

你可能感兴趣的:(Custom URL Schemes)