Search code examples
iosobjective-caccess-token

ios - How to handle NSURLConnectionDelegate?


I'm trying to get token with the help of given link. Please go through this link http://www.stevesaxon.me/posts/2011/window-external-notify-in-ios-uiwebview/

What is _data here? How to declare that?

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    if(_data)
    {
        [_data release];
        _data = nil;
    }
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    if(!_data)

    {
        _data = [data mutableCopy];
    }
    else
    {
        [_data appendData:data];
    }
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    if(_data)
    {
        NSString* content = [[NSString alloc] initWithData:_data
                                                  encoding:NSUTF8StringEncoding];

        [_data release];
        _data = nil;

        // prepend the HTML with our custom JavaScript
        content = [ScriptNotify stringByAppendingString:content];

        [_webView loadHTMLString:content baseURL:_url];
    }
}

Solution

  • Its NSMutablData Object which holds the response Data which you receive from your Request to Webservice

    Declare this in @interface of .h file

    NSMutableData *_data;
    
    @property (nonatomic, retain) NSMutableData *_data;
    

    and @synthesize _data; in .m file after @implementation line