我有以下代码:Objective - C的连接测试警告
//View guest list
-(IBAction) guestList:(id) sender{
NSString *connected = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"myURL"]];
//Waits a set peroid of time
wait(20000);
//Guest list is availible
if (connected != NULL){
CHARLIEAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate displayView:6];
}
//No network connection availible
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Network Connection!" message:@"Cannot establish internet connection." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
}
而且我得到以下警告:
//Waits a set peroid of time
wait(20000);
给我 - 警告:传递的参数1 '等待' 品牌从整数指针不进行强制转换
NSString *connected = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://photostiubhart.comoj.com/testconnection.php"]];
给我 -
警告: 'stringWithContentsOfURL:' 被弃用(在/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSString.h声明:384)
我做了我的测试和代码SEEMS工作正常,即使有这些警告。有没有办法根本去除这些警告?或者他们不重要?
我使用的Xcode 3.2.6以上版本
感谢,
杰克
不要使用'等待()'或'睡眠()'或朋友。这无意中阻塞了主线程。只需使用内置的连接方法即可。 – 2011-06-11 12:21:01