Push notification 城市飞艇推送通知问题

Push notification 城市飞艇推送通知问题,push-notification,urbanairship.com,Push Notification,Urbanairship.com,我正在开发一个带有phonegap的应用程序,但是我正在尝试通过带有NSUrlconnection的插件生成推送通知调用 通知与以下命令一起工作 curl-X POST-u:“-H”内容类型:application/json--data“{”device_tokens:[”“],“aps:{”alert:“Vikrant say Hello!”,“badge:“5”}” 现在,我正在尝试下面的代码相同 NSString *URL = @"https://go.urbanairship.com/a

我正在开发一个带有phonegap的应用程序,但是我正在尝试通过带有NSUrlconnection的插件生成推送通知调用

通知与以下命令一起工作 curl-X POST-u:“-H”内容类型:application/json--data“{”device_tokens:[”“],“aps:{”alert:“Vikrant say Hello!”,“badge:“5”}”

现在,我正在尝试下面的代码相同

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]];
        }
    }

这意味着它执行URL,但不发送用户名和密码。有人知道解决方案吗?

推送API调用通常使用主密钥作为密码进行身份验证,而不是应用程序密钥。将应用程序秘密视为可安全嵌入在应用程序中的受限访问代码;您永远不会将主密钥嵌入到应用程序中

但是,要使某些推送呼叫子集在没有主密钥的情况下可用,您可以在城市飞艇应用程序上启用允许从设备推送标志。这使您可以直接对具有应用程序机密的设备令牌进行推送调用。它不允许您推送别名、标签或进行完整广播,因为这些可能会被猜测,或者会给您带来很多麻烦

亚当

城市飞艇

推送API调用通常使用主密钥作为密码进行身份验证,而不是应用程序密钥。将应用程序秘密视为可安全嵌入在应用程序中的受限访问代码;您永远不会将主密钥嵌入到应用程序中

但是,要使某些推送呼叫子集在没有主密钥的情况下可用,您可以在城市飞艇应用程序上启用允许从设备推送标志。这使您可以直接对具有应用程序机密的设备令牌进行推送调用。它不允许您推送别名、标签或进行完整广播,因为这些可能会被猜测,或者会给您带来很多麻烦

亚当
城市飞艇

NSURL认证方法服务器信任替换为中的NSURL认证方法HttpBasic,以针对保护空间进行认证

-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
 return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPBasic];
}
canauthenticationagainstprotectionspace委托中的nsurauthenticationmethodservertrust替换为nsurauthenticationmethodhttpbasic

-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
 return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPBasic];
}

谢谢你的回复,亚当。我已经启用了“允许从设备推送”。我猜这是程序错误。谢谢你的回复。我已经启用了“允许从设备推送”。我猜这是编程错误。
-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
 return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPBasic];
}