2011-11-29 90 views
0

可能重复:
How to send the device token and app version to server发送设备令牌和应用程序版本服务器

我在我的应用程序实现的推送通知服务,但我无法发送设备令牌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); 
} 
+4

那么,究竟发生了什么问题?简单地说“不起作用”对任何人都没有帮助。你有没有调试变量的内容,你如何发送变量到你的服务器等。 –

回答

0

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

NSLog(@"%@",deviceToken) 
相关问题