SORU
14 ŞUBAT 2012, Salı


sendAsynchronousRequest nasıl kullanılır:sıra:completionHandler:

İki sorum olacak

BİRİNCİ BÖLÜM: Benim veritabanı için zaman Uyumsuz bir istek oluşturmak için çalışıyorum. Şu anda eş zamanlı olarak daha iyi ancak her iki yönde de ne olduğunu benim anlayış öğrenmek istiyorum bunu yapıyorum.

Şu anda bu Senkron telefonumu ayarladım.

- (IBAction)setRequestString:(NSString *)string
{
    //Set database address
    NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"http://127.0.0.1:8778/instacodeData/"]; // imac development

    //PHP file name is being set from the parent view
    [databaseURL appendString:string];

    //call ASIHTTP delegates (Used to connect to database)
    NSURL *url = [NSURL URLWithString:databaseURL];

    //SynchronousRequest to grab the data
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSError *error;
    NSURLResponse *response;

    NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    if (!result) {
        //Display error message here
        NSLog(@"Error");
    } else {

        //TODO: set up stuff that needs to work on the data here.
        NSString* newStr = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];
        NSLog(@"%@", newStr);
    }
}

Ne yapmam gerektiğini aramayı değiştir bence

NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

zaman Uyumsuz sürümü ile

sendAsynchronousRequest:queue:completionHandler:

ancak kuyruk ya da completionHandler geçmek için ne olduğundan emin değilim... çözümleri/Herhangi bir örnek büyük mutluluk duyacağız.

Bölüm iki: Çoklu görev hakkında yazılanları okudum ve eğer kesme varsa tabii benim bağlantı isteklerini tam yaparak desteklemek istiyorum. example Bu takip ediyorum

Bunu eğer bir kesme oluşursa daha fazla zaman kazanmak için nasıl açıklar, ben bu bağlantı uygulamak için ne yapıyor.. ama ne anlıyor? Eğer/bana bunu uygulamak için nasıl anlamaya yardımcı olmak için öğreticiler herhangi bir örnek varsa bu harika olurdu!

CEVAP
14 ŞUBAT 2012, Salı


Bölüm 1:

NSURL *url = [NSURL URLWithString:urlString];

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];

[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
    if ([data length] > 0 && error == nil)
        [delegate receivedData:data];
    else if ([data length] == 0 && error == nil)
        [delegate emptyReply];
    else if (error != nil && error.code == ERROR_CODE_TIMEOUT)
        [delegate timedOut];
    else if (error != nil)
        [delegate downloadError:error];
}];

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • dhcrr's channel

    dhcrr's chan

    2 Ocak 2007
  • RyanXLT

    RyanXLT

    22 Ocak 2011
  • SuicideSheeep

    SuicideSheee

    8 Ocak 2012