What is the “stringWithContentsOfURL” replacement for objective C?

后端 未结 4 757
刺人心
刺人心 2020-12-13 19:04

I found a tutorial on the net that uses the stringWithContentsOfURL command that is now deprecated as of iPhone OS 3.0. However I can\'t find out what I\'m meant to use inst

相关标签:
4条回答
  • 2020-12-13 19:31

    Thanks Greg, but for all those other beginners here is an example

    NSError* error = nil;
    NSString* text = [NSString stringWithContentsOfURL:TheUrl encoding:NSASCIIStringEncoding error:&error];
    if( text )
    {
        NSLog(@"Text=%@", text);
    }
    else 
    {
        NSLog(@"Error = %@", error);
    }
    
    0 讨论(0)
  • 2020-12-13 19:32

    For anything more than trivial, I recommend ASIHTTPRequest:

    http://allseeing-i.com/ASIHTTPRequest/

    0 讨论(0)
  • 2020-12-13 19:37

    It has been replaced with stringWithContentsOfURL:encoding:error: or stringWithContentsOfURL:usedEncoding:error:.

    0 讨论(0)
  • 2020-12-13 19:51

    Below code will remove your warning message........any question please let mo know.

    - (void) connectedToNetwork 
    {
        BOOL aflag = ([NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.google.co.in/"] encoding:NSASCIIStringEncoding error:nil]!=NULL)?YES:NO; 
        if (!aflag) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Sorry!....You are not connected to network " 
                                  delegate:self cancelButtonTitle:@"Exit" otherButtonTitles:nil];
            [alert show];
            [alert release];
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题