为什么我的NSURL对象等于nil?我的路是正确的 [英] Why does my NSURL object is equal to nil? My path is correct

查看:41
本文介绍了为什么我的NSURL对象等于nil?我的路是正确的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%lf,%lf&output=csv&sensor=false&key=swizzlec hops", coordinate.latitude,coordinate.longitude];
NSLog(@"urlString: %@", urlString); 
NSURL *urlFromURLString = [NSURL URLWithString:urlString];

我的日志是: http://maps.google.com/maps/geo?q=53.872874,27.527790&output=csv&sensor=false&key=swizzlec 啤酒花

我可以复制此URL并将其粘贴到浏览器中,并且可以,但是urlFromURLString = nil.但是,为什么?

I can copy this url and paste to the browser and its ok, but urlFromURLString = nil. But, why?

推荐答案

我相信您需要使用

stringByAddingPercentEscapesUsingEncoding:

在将urlString传递给NSURL之前.

on urlString before passing it to NSURL.

NSString *urlString = [[NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%lf,%lf&output=csv&sensor=false&key=swizzlec hops", coordinate.latitude,coordinate.longitude] stringByAddingPercentEscapesUsingEncoding::NSUTF8StringEncoding];

这篇关于为什么我的NSURL对象等于nil?我的路是正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆