【问题标题】:How to add device information while sending request to server?如何在向服务器发送请求时添加设备信息?
【发布时间】:2011-10-24 19:18:37
【问题描述】:

我想在向服务器发送任何请求以从服务器获取数据时添加有关 iOS 和设备型号的信息。谁能帮助我如何向服务器发送一些特定信息,以便服务器应该能够理解请求来自真实的 iPhone/iPad 设备、模拟器?

【问题讨论】:

    标签: iphone ios web-services http-headers security


    【解决方案1】:

    使用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 库与服务器连接,您可以在 ASIHTTPRequest.m 文件中获取此信息,如下所示

      #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
      

      【讨论】:

        猜你喜欢
        • 2016-02-14
        • 2017-04-12
        • 2015-11-18
        • 1970-01-01
        • 2022-09-26
        • 1970-01-01
        • 2023-03-07
        • 2021-10-26
        • 1970-01-01
        相关资源
        最近更新 更多