Je suis en train de développer une application avec phonegap, mais j'essaie de générer un appel Push Notification via le plugin avec NSUrlconnection. La commande ne fonctionne pas avec la commande suivante: curl -X POST -u ":" -H "Type de contenu: application/json" --data "{" device_tokens ": [" "]," aps ": { "alerte": "Vikrant dire Bonjour!", "badge": "5"}} » https://go.urbanairship.com/api/push/Problème de notification push d'un dirigeable urbain
MAINTENANT JE SUIS eSSAIE MÊME aVEC lE CODE CI-DESSOUS
NSString *URL = @"https://go.urbanairship.com/api/push/";
NSMutableURLRequest *req = [[[NSMutableURLRequest alloc] init] autorelease];
[req setURL:[NSURL URLWithString:URL]];
[req setHTTPMethod:@"POST"];
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"application/json; boundary=%@",boundary];
[req addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"{\"device_tokens\": [\"<devce token>\"], \"aps\": {\"alert\": \"Vikrant say Hello!\",\"badge\": \"5\"}}"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[req setHTTPBody:body];
NSURLConnection *conn = [NSURLConnection connectionWithRequest:req delegate:self];
finished = NO;
finishedWithError = NO;
if(xmlData == nil)
[xmlData release];
if(conn)
{
xmlData = [[NSMutableData alloc] retain];
while(!finished)
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
}
Ainsi, son URL HTTPS avec authentification du serveur. J'ai donc écrit les délégués.
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge
{
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
{
NSLog(@"Trust Challenge Requested!");
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
else if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPBasic])
{
NSLog(@"HTTP Auth Challenge Requested!");
NSURLCredential *credential = [[NSURLCredential alloc] initWithUser:@"<apikey>" password:@"<master key>" persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
[credential release];
}
}
Le problème est que la connexion n'accepte pas le nom d'utilisateur et le mot de passe. parce impressions ci-dessous la sortie
2000-01-01 11:07:09.-540 WIPT[500:307] From APN
[Switching to thread 13059]
2000-01-01 11:07:13.-986 WIPT[500:307] Trust Challenge Requested!
2000-01-01 11:07:14.-82 WIPT[500:307] didReceiveResponse
2000-01-01 11:07:14.-25 WIPT[500:307] connection
2000-01-01 11:07:14.-05 WIPT[500:307] connectionDidFinishLoading
2000-01-01 11:07:15.-958 WIPT[500:307] APN response data Authorization Required
Cela signifie qu'il exécute l'URL, mais pas la dose envoyer Nom d'utilisateur et mot de passe. Quelqu'un sait-il la solution
Merci pour la réponse Adam. J'ai déjà "permettre push de l'appareil" activer. Je suppose que c'est un défaut de programmation. –