2

我正在构建一个允许用户在屏幕上绘图的应用程序。我想添加网络功能,以便用户 A 可以在用户 B 的屏幕上绘图。我目前的计划是构建一个系统,其中我有自己的 UserOrNetworkTouch 对象,该对象可以基于真实的 UITouch 或来自网络的消息创建,并将应用程序中的所有绘图都基于 UserOrNetworkTouch 事件,而不是比 UITouch 事件。

我想要使​​用这个系统的另一件事是记录触摸,因此用户将能够按“记录”,然后稍后播放他们的绘图。

我想确保我不会在这里重新发明轮子。是否有任何可用的库可以为我处理部分或全部这些问题?

4

2 回答 2

3

You probably wouldn't send the UITouch objects over the network (although you could if you wanted). I might package then touch positions into a struct of some kind and just send that to decrease the amount of traffic you were sending. If you needed the entire UITouch object and all of its data then sure, send the object to your server.

You could use CFNetwork framework to send data to a server from your client application. If you do you should really try to use IPv6.

Apple have sample code here for working with CFNetwork streams

If you want to record the touch events, just use an NSArray or an NSDictionary if you wanted to store say the touch along with a timestamp for when the touch occurred.

Then just add each touch to the array or dictionary as the user makes them.

Update: I wouldn't waste your time with Apple's WiTap sample code. I've read though it before and there is a LOT of code in it that is just confusing and irrelevant if you want a simple client/server app up and running quickly. It will more than likely be way too confusing for you if you haven't done any network programming before.

I would get the network transfers working first, then if you like you can refer to WiTap for the Bonjour networking part so you can do auto discovery of the client and server. But add Bonjour support only after you have data steams working first.

于 2010-08-29T16:58:48.960 回答
0

A good place to start would be Apple's WiTap sample. It sets up a game over Bonjour and sends taps back and forth.

Also look at GameKit which'll make some of the networking even simpler.

A SQLite DB would be a great place to record events. Search for the 'fmdb' SQLite wrapper for a nice Objective-C wrapper.

于 2010-08-29T17:02:30.017 回答