将设备令牌和应用程序版本发送到服务器



可能重复:
如何将设备令牌和应用程序版本发送到服务器

我已经在我的应用程序中实现了推送通知服务,但无法将设备令牌id和应用程序版本发送到服务器。

提前谢谢。

这是我的代码

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    // Get Bundle Info for Remote Registration (handy if you have more than one app)
    NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
    // Prepare the Device Token for Registration (remove spaces and < >)
    NSString *deviceToken = [[[[devToken description]
                        stringByReplacingOccurrencesOfString:@"<"withString:@""]
                        stringByReplacingOccurrencesOfString:@">" withString:@""]
                        stringByReplacingOccurrencesOfString: @" " withString: @""];
    NSMutableString *urlString = [[BASE_URL mutableCopy] autorelease];
    [urlString appendFormat:@"traceDeviceTokenId?tokenid=%@&version=%@",deviceToken, appVersion];
    NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSString *postLength = [NSString stringWithFormat:@"%d", [urlString length]];
    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
    [request setURL:url];
    [request setHTTPMethod:@"POST"]; 
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
    [request setValue:@"text/xml; charset=utf-16" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:[urlString dataUsingEncoding:NSUTF16StringEncoding]];
    NSLog(@"Request xml>>>>>> %@", urlString);
    NSError *error; 
    NSURLResponse *response;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSString *responseXml = [[NSString alloc] initWithData:urlData encoding:NSUTF16StringEncoding];
    NSLog(@"Response xml>>>>>> = %@", responseXml);
}

您提供的代码中显然没有向服务器发送任何内容。要将其发送到服务器,可以使用SOAP。要检查令牌的格式是否正确,请写入

NSLog(@"%@",deviceToken)

相关内容

最新更新