Городской дирижабль - отправьте push с NSURLConnection

я работаю над простым прототипом и должен проверить отправку push-уведомлений с одного устройства на другое.

я написал по электронной почте Urban Airship, чтобы включитьРазрешить push с устройства " для моего заявления - и они включили его.

m пытается использовать NSURLConnection для отправки push-уведомления с устройства.

Это мой код:

- (void) test {
    NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://go.urbanairship.com/api/push"]];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

    NSDictionary * push = @{@"device_tokens":@[@""], @"aps":@{@"alert":@"TEST", @"sound":@"default"}};
    NSData * pushdata = [NSJSONSerialization dataWithJSONObject:push options:0 error:NULL];
    [request setHTTPBody:pushdata];

    [NSURLConnection connectionWithRequest:request delegate:self];
}

- (void) connection:(NSURLConnection *) connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *) challenge {
    if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPBasic]) {
        NSURLCredential * credential = [[NSURLCredential alloc] initWithUser:@"" password:@"" persistence:NSURLCredentialPersistenceForSession];
        [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
        [credential release];
    }
}

- (void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *) response {
    NSHTTPURLResponse * res = (NSHTTPURLResponse *) response;
    NSLog(@"response: %@",res);
    NSLog(@"res %i\n",res.statusCode);
}

Кто-нибудь еще сделал это успешно?

Ответы на вопрос(2)

Ваш ответ на вопрос