目标 - C连接测试警告

时间:2011-06-11 12:08:22

标签: iphone objective-c ios connection warnings

我有以下代码:

    //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);

给我 - 警告:传递'wait'的参数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

谢谢,

杰克

3 个答案:

答案 0 :(得分:1)

使用

NSError* error;  
NSString* connected = [NSString stringWithContentsOfURL:TheUrl encoding:NSASCIIStringEncoding error:&error];  

答案 1 :(得分:0)

您应该使用方法 -

+(id)stringWithContentsOfURL:(NSURL *)url encoding:(NSStringEncoding)enc error:(NSError **)error

例如 -

NSString* text = [NSString stringWithContentsOfURL:TheUrl encoding:NSASCIIStringEncoding error:&error];

希望它会对你有所帮助。

答案 2 :(得分:0)

尝试这样做:

-(IBAction)guestList:(id) sender{
    NSURL *requestUrl = [NSURL URLWithString:@"http://photostiubhart.comoj.com/testconnection.php"];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:requestUrl];
    NSData *loadTest   = [NSData dataWithContentsOfURL:requestUrl];

    if (loadTest == nil) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Network Connection!" message:@"Cannot establish internet connection."  delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];
        [alert release];
    } else {
        CHARLIEAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
        [appDelegate displayView:6];
    }
}