2011-11-29 89 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) 
相關問題