English 中文(简体)
取消Peter SDK的“协同关系”。
原标题:cancel a SynchronousRequest in iPhone SDK. (TIMEOUT Interval not working)

我问,这个论坛需要几个小时的时间来研究我的问题的想法/解决办法,但每次都是空洞的。

i) 采用下列方法制造了合成物:

    NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc] initWithURL:url];
    NSString *msgLength = [NSString stringWithFormat:@"%d", [params length]];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setTimeoutInterval:3.0];
    [theRequest setCachePolicy:NSURLRequestReturnCacheDataElseLoad];
    [theRequest setHTTPBody: [params dataUsingEncoding:NSUTF8StringEncoding]];
    NSData  *aData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];

the connection is established, and the data is retrieved successfully to aData. but, when there is a connection problem, or the server is not available, the request is attempting to connect for 75 seconds which is tooooo much time for the timeout interval, i have added the setTimeoutInterval parameter (with 3 seconds) but it does not affect the connection,

i saw some answers from people saying that i should use NSTimer, and runLoop, but it s not clear to me how this should be implemented.

PLEASE HELP!

用户正在等待75秒,然后才能获得一个时间差错的信息!

感谢您的帮助。

最佳回答

关于最低限值,很难在框架中编码,你可以将时间排在75秒以下。 Apple果的确如此,因为当你重新处理手机数据链接时,经常会出现大量滞后。

您希望在多数<>>中做些什么是使用超常的网络连接(因此,你的全球倡议确实冻结了),并允许请求在时间之前完成75秒。

http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html#/apple_ref/doc/uid/20001836-170129“rel=” Apple果指示,说明如何建立同步联系,这是一个很大的开端。

如果你真的想要确定非常短的时间,你可以使用<条码>。 缩略语

- (void)loadURL:(NSURL *)url {
    /* Set up the NSURLConnection here */

    [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(cancelURLConnection:) userInfo:nil repeats:NO];
}

- (void)cancelURLConnection:(NSTimer)timer {
    [self.connection cancel]
}

我不停在我的台上,这样,密码可能是gy,无疑是不完整的。 还指出,你可以轻松地利用一个时间来杀死一个同步的网络频率,因为同步的请求会阻挡坡道,而时间者在提出请求之前会打上火力。

问题回答

may I suggest having a look at the sample code from simpleURLconnections? From that code, the NSMutableURLRequest is sent using

 self.connection = [NSURLConnection connectionWithRequest:request delegate:self];

检索和发送数据(但参考了守则的其余部分)。 也许问题在于<条码> 修正了<>条码>,你可以避免使用这一条?

关于

你们可以使用一些法典,例如(从从事工作的大约一米)——但是一种全球变量:

- (void)someMethod {
    [[WSXMLRPCController sharedInstance] validateLicenseWithServiceURL:serviceUrl username:username password:password delegate:self];

    isFinished = NO;
    NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:10]; // break the loop after 10 seconds and not finished with the request from the call above ...
    while(!isFinished && [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:endDate]){
        if([endDate compare:[NSDate date]] == NSOrderedAscending){
            [self connection:nil didFailWithError:nil forMethod:nil];
        }
    }       
}


- (void)connection: (XMLRPCConnection *)connection didFailWithError: (NSError *)error forMethod: (NSString *)method {
   isFinished = YES;
}

- (void)connection: (XMLRPCConnection *)connection didReceiveResponse: (XMLRPCResponse *)response forMethod: (NSString *)method {   
   isFinished = YES;
}

也许不是最清洁的解决办法,而是行之有效的。 BTW 该法典正在使用“语言压力XMLRPCConnection”类别和代议制方法,但可能的话,与“国家措施”类别和代表方法相同。





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。