大家好我更新到iOS 4,但在我的应用程序使用:功能的IOS弃用4
NSString *connected = [NSString string withContentofURL:[NSURL URLWithString:@"http://myurl.com/myFile]];
,但现在我得到如下:
StringWithContentsofURL is deprecated !
我用这个来测试连接可用。
我能做什么?
感谢
大家好我更新到iOS 4,但在我的应用程序使用:功能的IOS弃用4
NSString *connected = [NSString string withContentofURL:[NSURL URLWithString:@"http://myurl.com/myFile]];
,但现在我得到如下:
StringWithContentsofURL is deprecated !
我用这个来测试连接可用。
我能做什么?
感谢
一个小Googling会给你这里的答案:
它已被替换为
stringWithContentsOfURL:encoding:error
...来源:What is the "stringWithContentsOfURL" replacement for objective C?
而且,今后请尝试拼写检查您的查询。
o真的,我会看看坦克和对不起 – sarlin13 2010-07-03 00:59:19
如iPhone OS2(因此这不是新的)的
[NSString withContentsOfURL: (NSURL*) url]
方法已被替换
+ (id)stringWithContentsOfURL: (NSURL *)url encoding: (NSStringEncoding)enc error: (NSError **)error
下面是使用新的签名的例子:
NSError* error = nil;
NSURL* url = [NSURL urlWithString: @"www.google.com"];
NSString* stringForUrlPath = [NSString stringWithContentsOfURL: url
encoding: NSUTF8StringEncoding
error: &error];
请参阅this为您的NSStringEncoding选项。
使用
NSError* error;
NSString *string = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
代替。苹果不应该包含stringWithContentsOfURL:
(无编码)开始。它在OS X上已被弃用了很长一段时间,因为这是导致非英语使用者头痛的原因。
也就是说,不要下载某些东西来测试连通性。相反,使用Reachiability。
可达性只会告诉你,如果你有3G或WiFi连接,而不是如果你可以到达一个网站。最好的检查一个地址是否可达是实现一个ping类。 Apple在这里有一个例子:http://developer.apple.com/mac/library/samplecode/SimplePing/Introduction/Intro.html – sdolan 2010-07-03 01:14:13
检查此堆栈问题:http://stackoverflow.com/questions/2039203/what-is-the-stringwithcontentsofurl-replacement-for-objective-c – Alan 2010-07-03 00:56:18