开发者

Fastest way for iPhone to contact Web server just to create a log entry

I track user activity in my iPhone app by having certain user actions call an almost empty Web page that the app does nothing with. Rather, attached to the URL are some querystring paramaters that tell me who's doing something and what it is (after I analyze the logs, that is).

I don't want launching the URL to slow down the app, so I prefer not to wait at all for any response. So after getting a bunch of device info and user action info and attaching that to a querystring, I call:

NSURLRequest *oRequest = [NSURLRequest requestWithURL: oURL cachePolicy: (etc) timeoutInterval: 2.0];
NSURLConnection *oConnection = [[NSURLCo开发者_如何学Pythonnnection alloc] initWithRequest:oRequest delegate: self];

Is this the fastest way to create a Web log entry while hindering my app the least?


You might put your request in the background by wrapping it in a selector and calling -performSelectorInBackground:withObject:. Or do the same within a one-off NSInvocationOperation.

This doesn't speed up the communication between the phone and the server, but it does put the request on a background thread, so that your app's user can keep doing whatever she is doing mostly unimpeded.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜