我已使用以下代码与Web服务器进行同步。它正在工作,但由于主队列中的getUnsyncTicketsFromServer方法调用,UI暂时冻结了。我试图在单独的队列中执行此操作。然后,它不会调用委托方法(requestReturnedData)。

[NSTimer scheduledTimerWithTimeInterval:320.0 target:self selector:@selector(syncTickets) userInfo:nil repeats:YES];

-(void)syncTickets{

   [self sendUnsyncedTickets];

   dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 6 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

       dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 6 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
          [self getUnsyncTicketsFromServer];
       });
   });


}

-(void)requestReturnedData:(NSData *)data{

 }


编辑-

-(void)getUnsyncTicketsFromServer{

    ServiceConnector *serviceConnector = [[ServiceConnector alloc] init];
    serviceConnector.delegate = self;
    [serviceConnector getTicketsFromServer];
    dataMethod = @"get";

}

最佳答案

@implementation YourClass () {
    ServiceConnector *_serviceConnector;
}

...

-(void)getUnsyncTicketsFromServer {
    _serviceConnector = [[ServiceConnector alloc] init];
    _serviceConnector.delegate = self;
    [_serviceConnector getTicketsFromServer];
    dataMethod = @"get";
}


如果您使用的是arc,我认为您的serviceConnector必须被释放,因此将对象存储为实例变量。

08-28 05:52