2011-10-24 14 views
1

iOSとデバイスモデルに関する情報を追加して、サーバにリクエストを送信して、サーバからデータを取得したいとします。どのようにサーバーにいくつかの特定の情報を送信する方法を助けることができるサーバーは、実際のiPhone/iPadデバイス、シミュレータからの要求を理解できるようにする必要がありますか?アクセスデバイス情報へサーバにリクエストを送信中にデバイス情報を追加するにはどうすればよいですか?

答えて

2

使用UIDevice currentDeviceオブジェクト:

モデル:

[UIDevice currentDevice].model; 

バージョン:

[UIDevice currentDevice].version; 

使用ASIHTTPRequest POSTサーバーにデータを送信します。

-(void)sendDataToServer{ 

     NSURL *url = [NSURL URLWithString:@"http://URL_TO_YOUR_SERVER"]; 

     ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 


     [request addPostValue:[UIDevice currentDevice].model; forKey:@"model"]; 
     [request addPostValue:[UIDevice currentDevice].version; forKey:@"version"]; 

     [request startSynchronous]; 

     NSError *error = [request error]; 
     if (!error) { 
      //NO error 
     }else{ 
      //Deal with error 
     } 
} 
2

あなたはiPhoneアプリケーションでサーバーとの接続のためのASIHTTPRequest 1.6.xのライブラリを使用している場合は、

#if TARGET_OS_IPHONE 
    UIDevice *device = [UIDevice currentDevice]; 
    deviceName = [device model]; 
    OSName = [device systemName]; 
    OSVersion = [device systemVersion];  
#else 
    deviceName = @"Macintosh"; 
    OSName = @"Mac OS X"; 
#endif 
以下のようにASIHTTPRequest.mファイルにこの情報を得ることができます
関連する問題