美文网首页
Custom URL Schemes

Custom URL Schemes

作者: Nirvana_icy | 来源:发表于2015-03-23 14:41 被阅读119次

    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

          本文链接:https://www.haomeiwen.com/subject/iylgxttx.html