【问题标题】:URLConnection Delegate methods are not getting called没有调用 URLConnection 委托方法
【发布时间】:2011-01-07 07:44:45
【问题描述】:

我在我的代码中使用了两个 Web 服务。 并在点击警报按钮时调用方法 我的代码是

  • (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 如果(按钮索引==1) { 如果(alertView==AlertDel) {

    [self DeleteFromServerDatabase];
    

    } } } -(void)DeleteFromServerDatabase {[加载 setFrame:CGRectMake(140, 210, 40, 40)]; [加载 setHidden:NO]; [加载器设置隐藏:否]; [self.view bringSubviewToFront:loader]; [self.view bringSubviewToFront:loading]; [加载开始动画]; NSString *devToken=app.iDevice; // NSString *devToken= [[UIDevice currentDevice] uniqueIdentifier]; 如果(开发令牌) {

    } 别的 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 代表。 请帮我解决这个问题

【问题讨论】:

    标签: objective-c


    【解决方案1】:

    你没有在你的 else 子句中做任何事情:

    if( theConnection2 )
    {
      webData = [[NSMutableData data] retain];
    }
    else
    {
    
    }
    

    您确定连接已正确初始化吗? NSURLConnection 文档说:

    返回值

    URL 请求的 URL 连接。如果无法初始化连接,则返回 nil

    另外,请确保您在主线程或您希望被回调的任何线程上开始加载:

    发送给委托的消息将在调用此方法的线程上发送。

    【讨论】:

      【解决方案2】:

      你忘了[theConnection2 start]

      【讨论】:

        猜你喜欢
        • 2012-09-26
        • 1970-01-01
        • 1970-01-01
        • 2013-12-03
        • 2020-11-14
        • 2020-11-28
        • 2017-05-04
        • 2012-11-10
        • 1970-01-01
        相关资源
        最近更新 更多