Urban Airship - Push senden mit NSURLConnection

Ich arbeite an einem einfachen Prototyp und muss testen, ob Push-Benachrichtigungen von einem Gerät auf ein anderes gesendet werden.

Ich habe Urban Airship eine E-Mail gesendet, um die Option "Push von Gerät zulassen" für meine Anwendung zu aktivieren - und sie haben sie aktiviert.

Ich versuche, NSURLConnection zu verwenden, um die Push-Benachrichtigung vom Gerät zu senden.

Das ist mein Code:

- (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":@[@"<token>"], @"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:@"<app key>" password:@"<app secret>" 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);
}

Hat das noch jemand erfolgreich gemacht?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage