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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 今天,听她的声音“打你哦”,真的很开心。也许等你长大了,我才能开始解释为什么选择离开,为什么选择不去做事情。也许有...
    清风悠然阅读 203评论 0 0
  • intrinsticContentSize是自定义UIView子类的固有大小,只要是重写了这个属性的UIView子...
    CoffeeKid阅读 528评论 0 1
  • 我有好多个梦想 一一都写出来了 写在本子上 好想写在心里 这样时刻想着 想着记着说着 一直到实现为止 把梦想刻在心...
    一只笨乌龟的日更日读阅读 115评论 0 0
  • 江南的春雨 像一串极细的珍珠 闪着亮光 飘飘忽忽 滑落在檐前
    高彬淳阅读 228评论 0 0