我有以下代碼: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