标签:
分享链接一般比较长,一般我们都有缩短网址的需求下面粘贴代码满足需求:
NSString *shareUrl = @"www.example.com";
NSString *str = [NSString stringWithFormat:@"http://is.gd/create.php?format=json&url=%@",shareUrl];
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:str];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60];
request.HTTPMethod = @"GET";
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSError * error = nil;
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
NSLog(@"%@",dic);
}];
标签:
原文地址:http://blog.csdn.net/qq11231325/article/details/42291187