我在代码中使用了两个Web服务。 并点击警报按钮调用方法 我的代码是
(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 如果(buttonIndex == 1) { 如果(alertView == AlertDel) {
[self DeleteFromServerDatabase];
} } } - (无效)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]; 如果(DEVTOKEN) {
} 其他 DEVTOKEN = @ “C677”; NSString * soapMessage = [NSString 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
{
}
} 但任何UrlConnection代表都没有被调用。 请帮我解决这个问题
答案 0 :(得分:1)
你在其他条款中没有做任何事情:
if( theConnection2 )
{
webData = [[NSMutableData data] retain];
}
else
{
}
您确定连接是否已正确初始化? NSURLConnection
文档说:
返回值
网址请求的网址连接。如果无法初始化连接,则返回
nil
。
另外,请确保在主线程或任何要重新调用的线程上启动加载:
发送给委托的消息将在调用此方法的线程上发送。
答案 1 :(得分:0)
你忘记了[theConnection2 start]