-1

1) I am building a software same as Boojam incident reporter.In that the incidents are recorded from an iphone and send it to the server.

2) After capturing all required information the reporter is suppose to click the send button in the iphone.

3) The data should be send to the database server in the school or organisation.

4) What I required is ,to know what are the technology available to transfer the data from iPhone to server.

Scope is simply I have to send the collected data in an Apple iphone to a server.I use Python language for logic.

Want to know what are the current technology used to perform the same.

Can any one list me technology about this link.

4

3 回答 3

2

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

于 2013-03-27T15:35:07.230 回答
2

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

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

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

于 2013-03-27T13:26:11.987 回答
2

通常从您的应用程序构建您需要的内容,序列化为 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
于 2013-03-27T13:27:32.687 回答