【问题标题】:Technology used to send information from iPhone to server [closed]用于将信息从 iPhone 发送到服务器的技术 [关闭]
【发布时间】:2013-03-27 13:18:23
【问题描述】:

1) 我正在构建一个与 Boojam 事件报告器相同的软件。其中事件是从 iphone 记录并将其发送到服务器。

2) 在捕捉到所有必需的信息后,假设记者点击了 iphone 中的发送按钮。

3) 数据应发送到学校或组织的数据库服务器。

4) 我需要的是,了解将数据从 iPhone 传输到服务器的可用技术。

范围只是我必须将Apple iphone中收集的数据发送到服务器。我使用Python语言进行逻辑。

想知道当前用于执行相同任务的技术是什么。

谁能列出有关此链接的技术。

【问题讨论】:

  • 不明白为什么要投反对票。
  • @Nathan 没有示例代码的问题是第一个被否决的受害者,因为它们似乎与编程无关。
  • @HuckleberryFinn 有时问题很简单,不需要任何令人沮丧的代码。
  • @Nathan 告诉反对者 ;)
  • @HuckleberryFinn 我也有几次被否决。只是因为有些人知道如何下推btn。

标签: iphone ios django ios4


【解决方案1】:

您需要的唯一技术是JSON 用于发送/接收收集的数据,并且在 django 端,您需要实现一个 API 以允许您的 django 应用程序能够发送/接收这样的请求。您可以使用 django-pistondjango-tastypie 创建 API。

【讨论】:

  • 一个疑问,JSON技术是用来从iphone发送/接收数据的,是对还是错
  • @user2086641 你的意思是苹果官方用它来构建内置的 iPhone 应用程序?我不知道,因为他们不喜欢开源他们的应用程序,无论如何JSON是数据传输的最佳选择,因为它在语言库和设备之间有广泛的支持。
  • Apple 正是出于这个原因提供了 NSJsonSerialization。 Json 很容易转换成 NSDictionary 或 NSArray 对象,然后可以读取/使用。它也适用于两种方式,因此您可以轻松地将 NSDictionary 或 NSArray 转换为可以 POST 到服务器的 Json 字符串。
  • 你说得对,我有个主意
【解决方案2】:

您需要在您的服务器上创建一个网络服务。 iphone会将数据“上传”到这个网络服务。

在 Python 中有很多方法可以做到这一点,这取决于您是否使用web development framework。你真的应该使用一个。用于此类任务的流行的是 django 和 flask。

在 iOS 端,您需要使用 NSURLRequest 将数据发布到服务器。

【讨论】:

    【解决方案3】:

    通常从您的应用程序中构建您需要的内容,序列化为 json 并通过您的 api 传递。这是我的一个示例,但它与服务器对话并返回一个简单的句子。这只是为了说明其中一些是如何在 xcode 中完成的。 (这是为了询问和接收数据,但你从中得到了想法)

    以下是 .h 和 .m 文件。

    //Step 1, add NSURLConnectionDataDelegate
            //.h
        @interface ViewController : UIViewController<NSURLConnectionDataDelegate>
        @property (strong, nonatomic) IBOutlet UILabel *answer;
        @end
    
    
    
    
    #import "ViewController.h"
    
    @interface ViewController ()
    {//step 2 local data objects
        NSMutableData*webData;
        NSURLConnection*connection;
    
    }
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        //Step 8 call (send) the request
        [self getData];
        // Do any additional setup after loading the view, typically from a nib.
    
    
        //NSDictionary*dict=[NSJSONSerialization se]
    }
    //Step 3 implement this method 
    -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
        [webData setLength:0];
    }
    
    //Step 4 append the connection data to your object
    -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
        [webData appendData:data];
    }
    
    //Step 5 Process results from request (called automatically when the data arrives)
    -(void)connectionDidFinishLoading:(NSURLConnection *)connection{
        //Main parse
    
        //Web data
    
        NSError*error;
    
        //Dictionary serialized (processed) using JSON (Way of encoding data from a web request)
        NSDictionary*data=[NSJSONSerialization JSONObjectWithData:webData options:0 error:&error];
    
        //If data is nil, then print error
        if (data==nil) {
            NSLog(@"%@",error);
        }
    
        //Print the data
        NSLog(@"%@",data);
    
        //Get the numerical result from the dictionary key name
        NSNumber*num=[data valueForKey:@"name"];
    
        //Convert number to string
        NSString*label=[num stringValue];
    
        //Set the label to this result
        _answer.text=label;
    
    }
    //Step 7, actually initialize the request
    -(void)getData{
        //I will break this down as if it where a generic method
        //Connect to the index.php file via this URL
    
    
        //Localhost/tutorials is the XAMPP folder on your computer
    
        //index.php is the php file
    
        //getLabel(int number){}
        //?f=getLabel (calling this method in the php file)
    
        //number=900
        //&value=900 is the parameter
        NSURL*url=[NSURL URLWithString:@"http://localhost/tutorials/index.php?f=getLabel&value=900"];
    
        //In the php file it does number*number and returns the results
    
        //URL request
        NSURLRequest*request=[NSURLRequest requestWithURL:url];
    
        //Set the connection
        connection = [NSURLConnection connectionWithRequest:request delegate:self];
    
        if (connection) {
            webData=[[NSMutableData alloc]init];
        }
    
        //*****Results of this request are processed by step 5
    
    }//Step 6, in case data connection fails
    -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
        NSLog(@"fail");
    
    }
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
    

    【讨论】:

    • 我可以知道这背后的任何特定技术吗?任何技术名称都可用如果可以,请给我先生
    • 这是来自您的应用程序。您使用 Objective-C 语言来构建应用程序(在苹果提供的 Xcode 中)。然后,您的应用程序中的此文件使用 Apple NSURLRequest api 和 JSON(使用 Apple 的 JSON api)。在您的请求的另一端(服务器),您使用您需要的东西。这个特定的例子与一个 php 文件进行对话
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多