开发者

Tips for a solid iPhone app using online services

I've been looking a开发者_StackOverflowt some very great online services iPhone app, such as the Twitter app. It's very robust, I can't crash the app no matter what I do.

When I try to build one, I always get crashes whenever there's something wrong, like no internet, wrong passwords, etc. Especially I notice that my app crashes when I switch between tab bars too quickly (when one of them is waiting for a response from the Twitter server, for example). How do I elevate this issue?

Is there any tips to build apps that never crashes like Twitter for iPhone?


Crashes tend to happen because of one of two reasons:

  1. You're referencing a deallocated object
  2. You have exceeded the amount of memory that you are permitted to use, either due to leaks, not lazy loading, or just an overall bad design.

As far as Internet connections go, this StackOverflow question has your bases covered there.

It's hard to say why making fast tab bar switches are causing your app to crash without code.


I have written such an app (a shopping app that uses the network for everything). Here are some tips:

  • Implement reachability so you know when the network is there (and keep checking it)
  • Run all network access asynchronously so the app does not freeze, thread networking when you can.
  • Send and receive the smallest amount of data per request. For example, in my shopping app, I only get 50 products per search, with only the SKU, description and price. Use JSON.
  • Round trip - request network data - as infrequently as possible, and at most once per screen. If you can do with the data you have in memory, do so.
  • Lazy load images
  • Cancel all network connections as soon as possible. As soon as the tab changes, kill any outstanding network access.
  • Cache, cache, cache. Its always quicker to get data locally.

Hope this helps.


One big differentiator between great network apps and terrible network apps is handling network latency. I can't stand apps where the UI stalls or becomes jerky when data is requested from the network, or where the entire interface is frequently locked up with an activity indicator. I tend to quit and uninstall these types of apps right away. Sometimes it is not entirely obvious how to allow the user to continue interacting with the app when some data is required from the network, but the hallmark of great design is that you think about these issues ahead of time. Really, those lengthy stalling activity indicators are a big "fail!" in my book.

I'm writing a network-data-heavy app myself, and implementing a really simple URL image cache singleton class and a "lazy" subclass of UIImageView that loads images in the background using an NSOperationQueue was really pretty simple, and the app runs smooth as glass :).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜