开发者

sending information from my iphone app to my computer

So I have a pretty simple problem, which I have no idea how to go about (kinda of new for everything h开发者_如何学运维ere). I am developing an iPhone app that I intend to use only myself - so think small for now :)Let's say all my app is doing is tracking my location every hour. All I want to do, is to be able to read this information not on the iphone, say on a file on my computer. How can I send this information from my app to a personal computer? I am guessing that I will need to set up some server / database or something on my personal machine?

Can someone please help with a quick step by step on how to go about that? I literally have no clue where to start...

Thanks!


You just need a http server and then you cam create HTTP GET/POST requests to url's set up on your machine. You can use the responses to send data back to the device.


You'll need to have a listener somewhere to send your data to. For instance, you could set up a communication class in your project which would be responsible for serving as the medium between your applications. You would then set up a listener on a server, or your machine that would listen for requests.

iPhone > Communication Class > Web service (.NET in this case)

You can use the NSURLConnection object to serve this purpose. E.g.

   - (void) sendSomethingToServer:(NSString*)myData{
        NSString*url = [[NSString alloc]initWithFormat: @"http://example.com/service.asmx/RecordData?myData='%@'", myData];
        [self createRequest:url];
        [url release];
    }

http://example.com/service.asmx/RecordData being the location and method on your web service.

Here's a generic request method I created which sets the headers as a JSON packet.

- (void) createRequest: (NSString*)urlFormatted {
    NSLog(@"Request Sent");
    NSURL *url = [NSURL URLWithString: urlFormatted];
    NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL: url];

    [request setHTTPMethod:@"GET"];
    [request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
}

And on the back-end, on your web server, you would have a method that recieves the data. Obviously you could use any technology you wanted on the server. In this example, I'm using .NET on Mono e.g.

[WebMethod(Description = "Generic Client Data)]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string RecordData(string myData)
{
  // Do something with data
}


Set up a Ruby on Rails server on your Mac. It's free and quite easy. Use ASIHTTPRequest to send data to the Ruby server. http://allseeing-i.com/ASIHTTPRequest/


If you just need to get the data back and forth, I believe you could use file sharing. Here's a tutorial on how to set that up:

http://www.raywenderlich.com/1948/how-integrate-itunes-file-sharing-with-your-ios-app

It would allow you to view the files in itunes and copy them back and forth when the iPhone is connected via USB. If all you need to do is to get a raw data file onto your computer, that would likely be a lot less overhead than having to build/run a full server just to transfer the file over.


Apple's can you help get started. Search for "networking" in the docs and develop a client on both sides which uses your own protocol.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜