I am using two web services in my code. and calling methods on tap of alert button My Code is
(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if(buttonIndex==1) { if(alertView==AlertDel) {
[self DeleteFromServerDatabase];
} } } -(void)DeleteFromServerDatabase {[loading setFrame:CGRectMake(140, 210, 40, 40)]; [loading setHidden:NO]; [loader setHidden:NO]; [self.view bringSubviewToFront:loader]; [self.view bringSubviewToFront:loading]; [loading startAnimating]; NSString *devToken=app.iDevice; // NSString *devToken= [[UIDevice currentDevice] uniqueIdentifier]; if(devToken) {
} else devToken=@"c677"; NSString *soapMessage = [NSStr开发者_运维技巧ing stringWithFormat: @"\n" "\n" "\n" "\n" "%@\n" "%@\n" "%@\n" "\n" "\n" "\n",bday.fname,bday.lname,devToken ];
NSURL *url = [NSURL URLWithString:@"http://72.167.96.135:8101/BirthDayWebService.asmx"]; NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [theRequest addValue: @"http://tempuri.org/DeleteBirthday" forHTTPHeaderField:@"SOAPAction"]; [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; [theRequest setHTTPMethod:@"POST"]; [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; theConnection2 = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if( theConnection2 ) { webData = [[NSMutableData data] retain]; } else { }
} but any of UrlConnection delegates are not getting called. Please help me out of this
You're not doing anything in your else clause:
if( theConnection2 )
{
webData = [[NSMutableData data] retain];
}
else
{
}
Are you sure that the connection was was properly initialized? The NSURLConnection
docs say:
Return Value
The URL connection for the URL request. Returns
nil
if a connection can't be initialized.
Also, make sure that you start the load on the main thread or whatever thread you want to be called back on:
Messages to the delegate will be sent on the thread that calls this method.
you forgot [theConnection2 start]
精彩评论