首页 > 代码库 > iOS 分享长网址转短网址
iOS 分享长网址转短网址
分享链接一般比较长,一般我们都有缩短网址的需求下面粘贴代码满足需求:
NSString *shareUrl =@"www.example.com";
NSString *str = [NSStringstringWithFormat:@"http://is.gd/create.php?format=json&url=%@",shareUrl];
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURLURLWithString:str];
NSMutableURLRequest *request = [NSMutableURLRequestrequestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicytimeoutInterval:60];
request.HTTPMethod =@"GET";
[NSURLConnectionsendAsynchronousRequest:request queue:[NSOperationQueuemainQueue] completionHandler:^(NSURLResponse *response,NSData *data, NSError *connectionError) {
NSError * error =nil;
NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingMutableContainerserror:&error];
NSLog(@"%@",dic);
}];
iOS 分享长网址转短网址