Tampilkan postingan dengan label tutorial. Tampilkan semua postingan
Tampilkan postingan dengan label tutorial. Tampilkan semua postingan

Jumat, 09 September 2011

How to make apps for iPhone

If you need a simple steps on how to make apps for iPhone well here it is. Developing iPhone applications is quite simple when you break the whole process into small steps and simple.

how to make apps for iphone


The five steps that follow review the entire process from beginning to end:

Step one. Idea of ​​development: The first step requires you to get ideas for application you are going to create. This is a very important step. This step can be accomplished by looking at demographic trends and determining your desired audience. Another aspect you must guard is to assess the competition if your idea is generic.

Step two. Package the idea: Then you want to take your idea and turn it into an application. Here are some questions to ask. What do you want your application to look like (eg user interface)? How do you want it to work? Are there specific features or capabilities you want it to be?

Step three. The Main Idea: Once you have fully developed your idea, you will need to find an experienced programmer. Find someone who has knowledge of programming and to pay a fee to small and medium to get your application developed and programmed. Explain to your programmer in detail exactly what you want in your particular application. All you have in steps one and two need to be given to your chosen programmer. In short you are acting as project manager and oversee the development rather than fiddling with the code yourself.

Step four. Submit your application: This step is quite simple and consists in submitting your application to the App Store, which can be done by Apple. You can then access a special control panel to view your download statistics and the money you made.

Step five. Market Your App: The final step is marketing your iPhone. This can be done with the various promotional methods such as spark conversations on relevant forums, or by spreading the word via social media.

Now you will realize that the development of iPhone applications is quite simple when you break it down into small steps. This brief overview will help you get started, but you need a tutorial more complex and deeper to help you succeed.

For more information about iPhone application development, see:

video How to create profitable iPhone Apps & games with no skills?
PDF How To Create iPhone Apps With No Programming skills?
Video $63,896.21 in 1 month thanks to the iPhone?
How I made $ 63,896.21 USD last month selling my iPhone Apps & Games? 


Back to:  apps for iPhone


Selasa, 16 Agustus 2011

Download apps for iPhone


You can install, add, and download apps for iPhone, iPod touch, or iPad from the App Store. Purchases are made through your Apple ID account. Many apps are free. All you need to do is buy first from apple apps store, synchronize and finally apply.

To purchase items from the iTunes Store, simply click on the Buy button for the item you want. The position is debited from your account and download to your iTunes library. Important: All sales are final. You can not cancel a purchase after clicking on Buy.

Steps to buy from the apps store:

1. in iTunes click appstore. In the menu you can also click app store then select home.

 

2. look for the item you want to buy.

For some items you can hear or watch a preview before you buy by double-clicking the title or clicking the Preview button.

 

3. Finally click buy. You need an account from iTunes to buy any apps.

 

Steps to sync and install to iPhone:

To sync and downloaded apps for iPhone, iPad and iPod touch you need to do the following. First connect your iPhone, iPad and iPad touch to your computer. Open the iTunes program. In iTunes, tick your device (under devices), and then select the apps button.

 

Choose Sync Apps, and then tick the application you want to synchronize. If you have iOS version 3.1 or later, you can also do the following. Drag and drop apps from the list on the left to the home screen on the right. Arrange your device's home screens by dragging app icons to where you want them to appear. When you are happy with your apps you can now click apply.

 

You can use the applications you download only on your iPod touch, iPhone, or iPad (not on your computer). Some applications may not work on all devices.

If you are connected to a 3G network or Wi-Fi, you can also buy applications directly from your iPod touch, iPhone, or iPad. For more information, see the documentation that came with your device.

Note: If you make changes to your iPhone, iPod touch or iPhone while connected to iTunes, you may need to log off your computer, plug it in before the changes appear in iTunes.


Back to:  apps for iPhone

Kamis, 11 Agustus 2011

Writing apps for iPhone

writing apps for iPhone 

how to create profitable iPhone Apps & games with no skills?
How To Create iPhone Apps With No Programming skills?
$63,896.21 in 1 month thanks to the iPhone?
How I made $ 63,896.21 USD last month selling my iPhone Apps & Games?

If you're reading this article, it is very likely that you've thought about writing apps for iPhone. You have probably heard everything I did before I started. Oh, it is very easy. Anyone can do it. Create only one fast and get rich in the App. Well, I can give you a slightly different perspective.



Write iPhone apps is easy if you're a professional software developer who has worked with Apple's development tools for years. If you're not a software developer, you are going to find it anything but easy. And if you're a developer, but you have not spent much time writing software for Apple, you are going to run into a big learning curve. 

First, you need to master the language. iPhone apps are written in Objective C. If you are a C programmer, well, it looks a little familiar, but still have a lot of learning to do. If you are not C programmer, I'm sure I hope you are ready to do some learning, and spend a lot of time on Google. I spent 90% of my "development" time for my first application surfing Google, looking desperately to figure out how to do something that seemed like it would be very simple. 

Second, you need to learn the development environment. iPhone applications are developed using two pieces of software. XCode is the soul of the code, add the project files, and run and debug. Interface Builder is where you design the user interface the body of your program. One of the trickiest parts of writing for programmer is to get the iPhone App Interface Builder interface jive when Xcode code when connected to. I strongly advice you to buy and read a good introductory book for iPhone application development. You really need to be at least a vague idea of how everything works together and the architecture of the iPhone app before you even start your first project. If you do not follow this advice, you are likely to screw up an incredible project. 

In addition to misconceptions about how "easy" it is writing apps for iPhone, you are probably thinking you are going to get rich. Who can blame you? You've probably read, if one man made hundreds of thousands of dollars out of one small application. Well, think of it like a lottery. Of course, few people get rich, but most people get little to nothing. I read somewhere that most app developers earned under $500. Getting rich quickly from their applications are possible because they were at the AppStore from the beginning and was the first of its kind in the app, or are in the very top of the rankings and has been a ton of publicity. 

Now, I do not think that I'm discouraging anyone from writing apps for iPhone. I have a lot of fun with it, and I learned a lot. But I'm a software developer for 8 years and it took months of work on my first app in my free time to get it done. And I really do not have any money yet. So stop and think first and do not believe everything you hear. 

Sean Miller is a.Net developer by day, and the iPhone App developer at night. 

You may like: Apps for iPhone

Rabu, 10 Agustus 2011

How to make an app for iPhone

how to make an app for iPhone 

Do you want to learn on how to make an app for iPhone? This is your chance to create iPhone apps with no programming experience.


video How to create profitable iPhone Apps & games with no skills?
PDF How To Create iPhone Apps With No Programming skills?
Video $63,896.21 in 1 month thanks to the iPhone?
How I made $ 63,896.21 USD last month selling my iPhone Apps & Games? 

Writing an iPhone application might seem like a hard thing to do if you are not too tech savvy with programming or the iPhone that you bought. This is the common downfall of many people having problem with when they would like to create an application. By creating an applfor your iPhone, you will benefits of enhancing all the basic function of the iPhone smartphone, share it with others, sell them at the AppStore and also be able to modify it however you would like so you can select what you want the application to do and how you would like it to do it. This is something that a lot of people did not think they were able to do, but now you can with a little help from the internet by searching for topic like how to make an app for iPhone and iPhone application programs. 

Downloading and installing iPhone Application Programs 

You want to download and install the iPhone apps installer to your phone all by yourself. You can choose a variety of iPhone application specific program to suit your needs and requirements when the time comes. By installing these programs on your phone, you can experiment, test and choose which one works the best for the type of application that you are going to be making. Devsecrets is is proven tutorial that provides you with everything that is needed without having to make the application maker yourself, or go through extensive extensive programming training to find out how to make an application on your phone. This can be something that is worthwhile and easy to use since they provide you with a walk through. Now is the time to earn money and start creating apps with no programming skills! 

The Tutorial and Training 

When it comes to going through the Devsecrets program the learning process is easy to understand, Just make sure that you have everything in front of you when the time comes. Having the right step by step creating application will be beneficial fory you and also very easy to use since you're able to go through a walk through tutorial on exactly what needs to be done in order to have an apps of your choice. The tutorial will teach you with tips, tricks, monitor you on how to make an application for iPhone of your choice. It will give you insights and knowledge of knowing how to create an iPhone application on your own later in this program. This is the start of your business by selling application to the AppStore. Finally it teaches you all at the same time. You have everything at hand when the time comes to create a wonderful to create application for your iphone that is useful and beneficial to friends and users.

Back to:  Apps for iPhone

How to delete apps on iPhone

In this tutorial you will learn how to delete apps on iPhone. After sometime you need to remove the application that has no use at all. The reason is your subscription expires or simply you do not need it anymore. Let me teach you how to do it.



For demonstration purposes in this tutorial from simplehelp.net they used the app Weatherbug.

Step 1. Locate your spring board and see which app to delete.

how to delete apps on iPhone

Step 2. Tap and gently hold down the icon of the app you want to remove. After a few seconds your screen will start to "shake" and an X will appear next to each of the applications you've installed via the App Store.

how to delete apps on iPhone

Step 3. Tap the X next to the icon of the appliation you want to delete. When prompted, choose Delete.

how to delete apps on iPhone

Step 4. Congratulate yourself you successfully remove the application.

how to delete apps on iPhone

Step 5. If the app is still in your iTunes application also, you will need to uninstall it from there - or else it will appear again the next time you sync. To hide the application permanently you need to set up your iTunes to not to sync all applications, only the ones that you want keep.

If the application is listed in your iTunes Applications as well, you'll want to remove it from there – or else it will re-install the next time you sync. Alternately you can keep the app in your iTunes Applications, and set iTunes not to sync all applications, just the ones you want to keep. See the Applications tab of your device the next time it's connected in iTunes for syncing options.

Step 6. NOTE: you can also re-order/move the apps on your iPod Touch, iPhone or iPad using a very similar process.

NOTE: you cannot remove certain applications – generally the ones that come pre-installed on your iPhone, iPod Touch or iPad – like Stocks, Maps, Safari etc.

Here are the video tutorials on how to delete apps on iPhone:

iPhone 2G
iPhone 3G
iPhone 4G

Back to:  Apps for iPhone

Kamis, 28 April 2011

Closing iPhone apps tutorials and solutions

Are you having a hard-time from closing iPhone apps abruptly? Here is the solution for you.


It is very irritating when you are in the middle of playing games then all of a sudden it crashed and close without any warning or notice.

Follow the step-by-step procedure below and you will be playing again games or running apps in no time.

1. First, disable automatic syncing on both computers.

2. If you have a jailbroken phone and are using SWAPTUNES application to maintain two seperate and distinct libraries on your iphone, make sure to swap to the right library for the right computer.

3. Here is where it gets a little tricky. Using the tabs on the sync screen make sure only the options that pertain to the computer you are currently using for syncing are enabled. For example if i sync my iphone to the PICTURES on my home computer, when syncing on my work computer i make sure the sync pictures option is disabled.

4. For applications however, SYNC ALL should be enabled. If you have some apps synced from home computer and some from work computer, make sure to respond in affirmative when itunes asks you whether you want an APP to be transferred to you current computer.

5. Now authroize your computer before starting to sync.

6. sync manually.

If you wonder where this problem came from I'll tell you. This closing apps automatically happen for people who are syncing their iPhone to two different computers.

Rabu, 27 April 2011

iPhone tips and tricks secrets revealed

How do you find your new iPhone? Do you know all of its features? If you think you are maximizing its features think twice. Today I will share to you iPhone tips and tricks secrets for you to optimize your iPhone experience.


I will enumerate every shortcuts and tricks you can do.

1.   Page down -When not using a zoomed-in display, double-tap towards the bottom of the screen. The page will re-center around your tap. Make sure not to tap a link!

2.   Locate your lost iPhone - If you’ve lost your iPhone, Find My iPhone can help you locate it on a map and protect its data. Display  a message on its screen, remotely set a passcode lock, or initiate a remote wipe to delete your data.

3.  Save images from the web- In Safari, touch and hold an image to save it to your Camera Roll or copy it to paste into an MMS or email.

4.  Force Quit - To actually close (or Quit) an application, HOLD the Home button for about 4-8 seconds while in the application. Apparently this will save battery usage and will also keep it cooler.

5.  Web Usage - If your favorite 'news' sites offer an RSS feed, bookmark and use that on your iPhone (not update your bookmarks because your iPhone will need to revise the link and use the .mac reader). This can make browsing, even while on EDGE much faster.


6.  Choose your wallpaper - In Settings, choose Wallpaper, tap the image of the Lock and Home screens, then tap one of your photo albums or tap Wallpaper for the Apple-designed images. Find the image you want, tap Set, and then choose whether to use it as wallpaper for your Lock screen, Home screen, or both.

7.  Scroll to the top fast - In Safari, Mail, Contacts, and many other apps, tap the status bar at the top of the screen — which displays the network information, time, and battery level — to scroll quickly to the top.

8.  Address Book - Create several subgroups, this can speed up the location of a contact given the lack of an actual search function. I use Work, Family, iPhone and it automatically puts the All Contacts group. Unfortunately I do not know how to do this on a PC. Hopefully someone can post.

9.   Bookmarks - Create a separate folder / section for all your iPhone web sites. This makes is easy to locate them while browsing the we on your iPhone.

10.  Lock the screen orientation - Double-click the Home button to bring up the multitasking interface, then swipe from left to right. Now tap the portrait orientation lock once to turn it on and again to turn it off.

11.  Drop a pin - In Maps, touch and hold anywhere on a map to drop a pin so you can find an address, get directions, or see street view for that location.

12.  Safari - Well just point your iPhone browser to a Video on google video and choose download for iPod/PSP and you can watch it right there in safari. This also shows that you can also watch videos in the vertical position not just landscape.

13.  Safari - Examining the URL  To peek at a link's destination, touch and hold the link for a few seconds. You can also do this with images to see if they are linked. If a link appears and you don't want to activate it, just slide your finger away until the destination text disappears.


14.  Tap to zoom the camera - Tap the screen to bring up the zoom control, then use the slider to zoom in and out up to 5x.

15.  Add PDFs to iBooks - From a Mail message or a web page, touch and hold the PDF icon or link, then select “Open in iBooks.”

16.  Safari - Manual zoom. This is probably one of the most-advertised Safari features (along with the flip-the-phone-on-its-side-trick) but it's worth mentioning again. To zoom into a Safari page, put your thumb and forefinger on the screen and move them apart. To zoom out, pinch the fingers together after starting with them apart.


17.  Safari - Stopping a scroll. After flicking a page to get it to scroll, you can tap the page at any time to stop that movement. Don't forget, you can also manually drag the screen display to reset the part you're viewing.


18.  Use the compass with maps - Tap the Location button in Maps twice to use the built-in compass to orient the map based on the direction you are facing.

19.  Create web clips - To add a website to your Home screen, visit the page in Safari and tap the plus sign at the bottom of the screen. Now tap “Add to Home Screen.”

20.  Safari -  Zoom a column. You can zoom text columns as well as pictures. Double-tap on the column to fit it to the display. Double-tap again to return out of the zoom. Not only does Safari zoom block-quoted text independently of regular text but if you move your finger after the first double-tap-to-fit, it interprets the next double-tap as a re-center page command rather than a return-to-previous-zoom. Smart.

21.   SafariZoom onto a single picture. Double-tapping images in Safari zooms them to fit your iPhone display. If the picture is linked to a URL, this can prove a little tricky but it works great for non-linked images. Double-tap again to return to the unzoomed display.

22.   Safari - Jump to the top. Double-tap the very top of the screen, just below the time display to pop back to the top of the page


23. Learn some keyboard tricks.
  • Tap the space bar twice, and iPhone adds a period and capitalizes the next word.
  • To enter a number or symbol quickly, touch and hold 123, then select the key you want. Lifting your finger returns you to the alphabet keyboard.
  • Touch and hold a letter to reveal a list of special characters.
24.  Scrub through audio and video.
When you’re watching a video or listening to music or a podcast, the scrubber bar lets you skip to any point along the timeline. You can adjust the scrub rate from high-speed to fine scrubbing by sliding your finger down as you drag the playhead along the scrubber bar.

25.   Safari: - Page down. When not using a zoomed-in display, double-tap towards the bottom of the screen. The page will re-center around your tap. Make sure not to tap a link!


26.   Safari - To email a page to someone tap on the address bar. The Share button on the top left will create a message for you!


27.  Keep your inbox clean.
In Mail, you can delete or move messages in batches. From your inbox, tap Edit, select the messages you want to organize, then tap Delete or Move.

28.   Take a picture of your screen.
Press and hold the Home button, then press the Sleep/Wake button. Your screen flashes and the picture of your screen appears in your Camera Roll.

29.   Safari - Doesn't provide scroll bars for text area form fields and scrollable areas in a text page. An example of this is the field I'm using to type this message in. Dragging a single finger on the page scrolls the page. If you want to scroll one of the areas I just described, use two fingers


30.  Google Maps -  Typing in the three letter airport code while in maps will bring the airport up on the map. So if you are trying to view a map of say Renton, WA. Typing SEA (or sea) will bring up the Seattle airport. It's relatively quick to zoom out, recenter over Renton, and zoom in again. It seems to recognize all primary and secondary US airports and many overseas airports as well.

31.  Create an iPod playlist -
In the iPod app, tap Playlists, then tap Add Playlist and give it a name. Now tap any song or video to add it to the playlist. You can add individual songs, entire albums, or all songs by an artist.

32.  Tap to focus the camera.
While shooting video or photos, tap the screen where you want to focus. iPhone will also adjust the exposure and white balance automatically.

33.  iPhone - To use the CAPS LOCK feature, make sure it is enabled in the General Settings. To use it, simply double-tap on the shift key. The shift key will turn blue.

 34.  iPhone - The home button can be used to access unlocking instead of sleep wake


35.  iPhone -  Keeping the favorites screen open allows you to unlock the screen then dial with three motions


36. Swipe to delete.
Delete email messages and text conversations without opening them. Just swipe across the email or conversation and a Delete button appears. Tap it to delete.

37.   Print wirelessly from iPhone.
AirPrint makes it easy to print email and web pages right from your iPhone to your AirPrint-enabled printer. To print an email, just tap the Reply icon and select Print. To print a web page, tap the Action icon and select Print. You can also print photos, documents, and more.

38.  Cut, copy, and paste.
Find the text you want to edit in a note, email, web page, or other app. You can select a word by double-tapping it, and select more or less text by dragging the grab points. Then tap to cut, copy, or paste. To undo an edit, shake iPhone, then tap the Undo button.

39. Examining the URL. To peek at a link's destination, touch and hold the link for a few seconds. You can also do this with images to see if they are linked. If a link appears and you don't want to activate it, just slide your finger away until the destination text disappears.

40.   Manual zoom. This is probably one of the most-advertised Safari features (along with the flip-the-phone-on-its-side-trick) but it's worth mentioning again. To zoom into a Safari page, put your thumb and forefinger on the screen and move them apart. To zoom out, pinch the fingers together after starting with them apart.

41.   Display character count in text messages.
In Settings, tap Messages, then tap the Character Count switch. The count appears as you type when your message exceeds two lines. You may want to do this when carrier fees apply.

42.   Place a call on hold.
On iPhone 4, touch and hold the Mute button to put a call on hold (GSM model only).

43.  Stopping a scroll. After flicking a page to get it to scroll, you can tap the page at any time to stop that movement. Don't forget, you can also manually drag the screen display to reset the part you're viewing.

44.   Zoom a column. You can zoom text columns as well as pictures. Double-tap on the column to fit it to the display. Double-tap again to return out of the zoom. Not only does Safari zoom block-quoted text independently of regular text but if you move your finger after the first double-tap-to-fit, it interprets the next double-tap as a re-center page command rather than a return-to-previous-zoom. Smart.

45.  Get back to your draft.
In Mail, touch and hold the Compose button to switch to your last saved message draft.

46.  Read the iPhone User Guide.
For more tips, tricks, and instructions, tap the Bookmarks icon in Safari, then select iPhone User Guide.

47.  Zoom onto a single picture. Double-tapping images in Safari zooms them to fit your iPhone display. If the picture is linked to a URL, this can prove a little tricky but it works great for non-linked images. Double-tap again to return to the unzoomed display.

48.   You can get on the internet DURING a call! You can only do this if your connected to a WIFI network (it wont work via edge), just hit the home key and click on Safari. Now your surfing while talking! The person on the other end can't hear the keyboard clicks either!

49.   Alarm Tricks
When the alarm (Clock) wakes you up in the morning, touching the sleep/wake button will "snooze" and sliding the wake up slider will turn off the alarm.

50.    Battery
This may have been mentioned, but it is worth saying again. I turned off my Wifi and the difference in my battery consumption has been amazing. Also I set my emal frequency to manual. I realize for those of you who depend on email this may not be a good option, but for those like me who only need to check a few times a day it helps conserving the battery.

 If you have more iPhone tips and tricks please post here so we could update our list and add more functionality to our iPhone rich features.

Kamis, 14 April 2011

How to organized iPhone apps Tutorial

In this tutorial you will  learn by watching the easy way on how to organized iPhone apps.


There are many ways on organizing applications on your iPhone. I bet this the the easiest way to that. Just watch closely and you will learn how to make your iPhone pages clean and free from clutter.

iTunes iPhone Backup Tutorial

In this iTunes iPhone Backup Tutorial you will learn the step-by-step procedure to carry to save purchase apps to your iTunes.


To backup apps from your iPhone to iTunes:

Step 1. Right click on your iPhone in the left hand explorer bar

Step 2. Right click on your iPhone in the left hand explorer bar



Step 3. You should see a progress bar in iTunes and your phone should read “Sync in Progress”

Step 4. If everything went as planned, all of your applications that were purchased on your iPhone should now appear in iTunes





Please do like, tweet, or bookmark if you found this iTunes iPhone Backup Tutorial useful.

Sabtu, 02 April 2011

Deleting iPhone apps tutorial

Hi again to you dear readers = )  My tutorial today is about deleting iPhone apps temporarily or permanently


First to delete iPhone apps temporarily to save apps space is by pressing down the apps holding it until such time the icon begin shaking.  You will notice that there will be a little black and white x appearing at the right hand corner.  Hit the x mark and it will delete the application temporary, but will come back when you sync your phone again to iTunes.

Next if you want to delete the apps permanently you will have to undergo two steps.  First you need to Un-Sync the apps then proceed to deleting the apps.  Read on to do these two steps.

To Un-Sync the apps you need to connect your iPhone to PC and open up iTunes.  From your iTunes select your iPhone and then click the application tab in its section.  In the application tab you will see all the apps that you installed.  Notice the box next to the application,  if it is checked it means that the app is in sync with app.  The app with no check means it is not sync with the iTunes.

Now that you know, which is sync and, which is not, we will proceed to deleting the apps permanently. Look for the library section in the left hand bar on your iTunes. Go to the application section and select it. You will notice that all of your apps will have icons on large black plain. All you have to do is right click the application and select the delete option. The program will ask you if you want to delete the app permanently and send it to Recycle Bin. Click move to Recycle Bin instead of keep files and finally you remove the application permanently.
 

Rabu, 12 Januari 2011

How to install iPhone apps

Installing the iPhone apps how to is easy, once you learn the process. iPhone is one of the most loved and highly electronic devices over the last decade. Applications for the iPhone has become very popular. Today iPhone App is almost everything you could possibly dream.


Step 1: Register to ITUNES

Before you can download the iPhone app, you need iTunes account. On your iPhone, go to "store" under the "settings ". Registration is simple, and it will be completed within a few minutes.

Step 2. Connect to internet

Next, make sure that your iPhone is connected to the Internet. You need to be on the network and login to the App Store. If you want to start to app store, simply tap the blue icon for the App Store.

Step 3. Search for the apps that you might like.

Now comes the exciting part! You can browse the available iPhone apps to find one that you want. You can view different categories or you can view the most popular applications, or display applications. For each app, you can read more about it to learn what it takes.

step 4. Buy and download

To start the download process, select the price and then when it says "Buy Now". At this stage, you probably asked to provide information on iTunes. When you do, the download starts immediately.

step 5. Install and enjoy

After the download completes (you will see a progress status bar in the Meantime), all it takes is Another tap on the screen to install. Then you are free to enjoy your new iPhone app!

Just follow the steps on how to install iphone apps above and you will have new features on your iPhone in no time.

You may like:  Top travel apps for iPhone

Senin, 24 Mei 2010

Downloading Images for a Table without Threads

It is common practice in many networking libraries in many languages to spawn threads to handle asynchronous communications in the background while the rest of the program continues to function. Although this approach does work on the iPhone, it's really not the right way to do it. I've recently run across two different blog postings that show how to download images for display in an iPhone table view, and they both did synchronous network communications using threads.

Here's my Public Service Announcement for today: Don't. Please… just, please don't, okay? Don't spawn threads for asynchronous communications unless you would have used threads in the same situation if there was no network code..
Note: A few people have suggested that this post is misleading because threads are used behind the scenes. Yes, it is true that the iPhone OS will spawn a small number of non-main threads as the result of using certain networking APIs. You still should be using the asynchronous APIs for your network communications and should not be spawning threads so you can make synchronous networking calls without blocking.
I don't like to knock other people's tutorials. In programming, there are multiple ways of doing nearly everything, and often more than one approach has merit in certain situations, so I'm always hesitant to say that the approach someone else uses is "wrong" if it works. But, this is one of those cases where there is a clear and compelling reason not to do it one particular way. However, because the "right" way is not necessarily intuitive, especially for people whose networking experience has all been thread-based, I thought it worth a short tutorial to show how to download asynchronously for display in a table without spawning any threads.

But first, why shouldn't we use threads this way? Well, simply put, threads have overhead. It's not a huge overhead, but it's non-zero and, in fact, it's non-trivial given the processing power and physical memory available on iPhone OS devices. The overhead of threading absoulutely makes sense in some situations; asynchronous networking is not one of those situations. Apple provides asynchronous APIs specifically for this purpose and they're designed to give the best performance in light of available system resources.

But, don't take my word for it. Here is what Apple says on the matter, in a guide written to help Windows programmers make the transition to programming for the Mac (emphasis mine):
One of the complexities of socket use involves the use of separate threads to handle the exchange of data. In a server environment, where hundreds of sockets are open simultaneously, the code that checks all these threads for activity may cause a significant performance hit. In addition, with threads, data synchronization is often an issue, and locks are often required to guarantee that only one thread has access to a given global variable at a time.

[...]

Event-driven code is more complex than code using blocking threads, but it delivers the highest network performance. When you use a run loop to handle multiple sockets in the same thread, you avoid the data synchronization problems associated with a multiple-thread solution.
When Apple says something as specific as this, they usually have a darn good reason for it. This is Apple's polite way of saying "don't use threads for networking, you idiot". They're a lot more polite than I am, obviously.

As you probably know, your application's main thread (the one that gets created automatically when your application is launched) has a loop (contained in UIApplication) that's always running. It's called your application's run loop and it keeps running as long as your application is executing. Every time through this loop, UIApplication does a whole bunch of stuff. It checks for inputs from the hardware and mach messages from the OS, for example, and it looks to see if there are any NSTimers running whose targets need to be called. Among the tasks it does is to check for incoming network data. There are more things the run loop handles, but that last one is the important for today's discussion.

Conceptually speaking, CFNetwork is not the easiest framework to grasp, but it is extremely efficient. It can handle hundreds, maybe even thousands of simultaneous downloads without causing the main thread to seize up. It's considerably more efficient than using synchronous network calls on a thread and not really any harder once you know how to do it.

Let's Try Downloading on the Main Thread



I've written a small iPhone app that downloads images from Deviant Art. You just enter somebody's Deviant Art username into a text field and the application will grab the the images in that person's gallery, download them asynchronously, and display each one in the table once it's finished downloading:

Screen shot 2010-05-24 at 4.28.42 AM.png

Notice that there's an activity indicator showing that some images are in the process of being downloaded. This is all happening on the main thread. I spawn no explicit threads in this application, and yet the UI stays responsive. You can also tap a row to view the image larger, but that's not really important to the process being illustrated.
Note:Although most DeviantArt galleries are SFW, there are many that aren't, so just be aware of that. Edit: Turns out that warning was unnecessary - since we haven't authenticated, DeviartArt filters out all the NSFW images automatically.

Creating the Download Object


In your own applications, you may approach things somewhat differently, but for this sample application, I'm going to put the code to download the image in its own data model class called DeviantDownload. I'm going to override the accessor method for the image so that the first time that accessor is called, it will kick off the download. If I call the image accessor method and get nil, the calling code can make itself the download's delegate to get notified when the download finishes.

In this application, downloads don't get triggered until the first time an image scrolls onto the screen. That may not be what you want in your application, but it will keep things nice and simple for this example. Here's the declaration of our download class:

#import <Foundation/Foundation.h>

#define DeviantDownloadErrorDomain @"Deviant Download Error Domain"
enum
{ DeviantDownloadErrorNoConnection = 1000,
}
;

@class DeviantDownload;
@protocol DeviantDownloadDelegate
- (void)downloadDidFinishDownloading:(DeviantDownload *)download;
- (void)download:(DeviantDownload *)download didFailWithError:(NSError *)error;
@end



@interface DeviantDownload : NSObject
{ NSString

*urlString; UIImage

*image; id <NSObject, DeviantDownloadDelegate> delegate;

@private NSMutableData

*receivedData; BOOL

downloading;
}

@property (nonatomic, retain) NSString *urlString;
@property (nonatomic, retain) UIImage *image;
@property (nonatomic, readonly) NSString *filename;
@property (nonatomic, assign) id <NSObject, DeviantDownloadDelegate> delegate;
@end


Pretty straightforward, right? I define an error domain and an error code for the one error situation our application generates (the rest come from NSURLConnection). After that, I declare a protocol that defines the methods our delegate has to implement. There are only two: one that gets called when the download finishes successfully, and another that gets called if it fails. In the sample application, our error checking is minimal, but you will do real error checking in your apps, right? RIGHT?! Yes, you will, because that's the way you roll. In a real app, you might also add a third delegate method that to inform the delegate what percentage of the download is complete, but I'll leave that one as an exercise for the student.

Next, I declare the DeviantDownload object, which only has four instances variables, one of which is private. urlString is the url of the image to download, image is the downloaded image, and delegate is the object that wants to get notified about the status of the download. Finally, receivedData is just a buffer to hold the downloaded data until I have it all and can create the image from it.

Okay, let's look at the implementation of our download object:

#import "DeviantDownload.h"

@interface DeviantDownload()
@property (nonatomic, retain) NSMutableData *receivedData;
@end


@implementation DeviantDownload
@synthesize urlString;
@synthesize image;
@synthesize delegate;
@synthesize receivedData;
#pragma mark -

- (UIImage *)image
{
if (image == nil && !downloading)
{
if (urlString != nil && [urlString length] > 0)
{
NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:self.urlString]];
NSURLConnection *con = [[NSURLConnection alloc]
initWithRequest:req
delegate:self
startImmediately:NO]
;
[con scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSRunLoopCommonModes
]
;
[con start];



if (con)
{
NSMutableData *data = [[NSMutableData alloc] init];
self.receivedData=data;
[data release];
}

else
{
NSError *error = [NSError errorWithDomain:DeviantDownloadErrorDomain
code:DeviantDownloadErrorNoConnection
userInfo:nil
]
;
if ([self.delegate respondsToSelector:@selector(download:didFailWithError:)])
[delegate download:self didFailWithError:error];
}

[req release];

downloading = YES;
}

}

return image;
}

- (NSString *)filename
{
return [urlString lastPathComponent];
}

- (void)dealloc
{
[urlString release];
[image release];
delegate = nil;
[receivedData release];
[super dealloc];
}

#pragma mark -
#pragma mark NSURLConnection Callbacks
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivedData appendData:data];
}

- (void)connection:(NSURLConnection *)connection
didFailWithError:(NSError *)error
{
[connection release];
if ([delegate respondsToSelector:@selector(download:didFailWithError:)])
[delegate download:self didFailWithError:error];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
self.image = [UIImage imageWithData:receivedData];
if ([delegate respondsToSelector:@selector(downloadDidFinishDownloading:)])
[delegate downloadDidFinishDownloading:self];

[connection release];
self.receivedData = nil;
}

#pragma mark -
#pragma mark Comparison
- (NSComparisonResult)compare:(id)theOther
{
DeviantDownload *other = (DeviantDownload *)theOther;
return [self.filename compare:other.filename];
}

@end


To make memory management more readable, I first declare a property for receivedData in a class extension. This creates a property that is accessible in my class but that isn't advertised to other classes. After that, I synthesize the four properties (three public declared in the header and one private declared in extension)

The first method I've written is an accessor for image. Remember, @synthesize creates an accessor and mutator if one doesn't already exist in your code, so by providing an accessor but not a mutator, @synthesize will create a mutator for me, but will use this method as its accessor. I don't want to download more than once, so I use the instance variable downloading to keep track of whether I've already kicked off a download. If image is nil and I haven't previously kicked off a download, I kick one off asynchronously.

At the end of the method, I return image, even though it will still be nil until the download is complete. That's okay, that will be the calling code's indication that they should become the download's delegate.

The next method, filename just returns the last part of urlString, which is the filename. I don't want to display the whole URL in the table.

The dealloc method is pretty standard stuff, so we can skip it.

The next four methods are the asynchronous callbacks for NSURLConnection. The first, connection:didReceiveResponse: is called when a connection is made. I set the length of receivedData to zero here because if there's a redirect, this will get called multiple times and I want to flush out the payload from the earlier redirected connections. That extra data, when it exists, would prevent our image from being created.

connection:didReceiveData: gets called periodically during the download, whenever there's data sitting in the buffer for us. All I do here is tack the newly received data onto the end of what's already been received.

In connection:didFailWithError:, I release the connection and notify our delegate. Because this is a data model object, I don't show an alert or anything. Dealing with the error isn't this object's responsibility. Once it reports it, its job is done; it'll let the controller figure out what to do with the error. This keeps our object firmly in the "model" component of the MVC paradigm and maximizes the chances I'll be able to reuse this object at some point.

Finally, in connectionDidFinishLoading:, I create an image from the received data, assign it to the image property and notify our delegate.

The last method, compare: is implemented to let us determine if two DeviantDownload objects represent the same file. I'll use this to look at two downloads and see if they are downloading the same file, which we don't want to do. Deviant Art uses a server farm to serve images, so the same image can have multiple URLs, but for a particular user, the filename must be unique, so I compare that.

Using the Download Object


In the table view controller, I pull down a list of the URLs for the given user. I'm not going to go into detail of the logic that does this, but in short, I asynchronously pull down JSON data for the user's gallery in chunks of 24 images, creating new DeviantDownload objects for each one and adding them to the NSMutableArray that drives our table. In our tableView:cellForRowAtIndexPath:, here's what I do:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{

DeviantDisplayCell *cell = (DeviantDisplayCell *)[tableView dequeueReusableCellWithIdentifier:[DeviantDisplayCell reuseIdentifier]];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"DeviantDisplayCell" owner:self options:nil];
cell = loadCell;
self.loadCell = nil;
}

DeviantDownload *download = [downloads objectAtIndex:[indexPath row]];
cell.cellLabel.text = download.filename;
UIImage *cellImage = download.image;
if (cellImage == nil)
{
[cell.cellSpinner startAnimating];
download.delegate = self;
}

else
[cell.cellSpinner stopAnimating];

cell.cellImageView.image = cellImage;
return cell;
}


The first part of this method is standard table view cell stuff, but then I grab the DeviantDownload object for the row being displayed. If the image accessor method returns nil, I show the cell's activity indicator (aka "spinning wait-a s-cond doohickey") and assign the controller as the delegate of the download. If the object doesn't return nil, I make sure the activity indicator isn't animating and stick the download's image into the cell's image view. The first time this gets called for any particular row, image will return nil, which will trigger the download to start.

I also implement the DeviantDownload delegate method that gets called when the download is complete:

- (void)downloadDidFinishDownloading:(DeviantDownload *)download
{
NSUInteger index = [downloads indexOfObject:download];
NSUInteger indices[] = {0, index};
NSIndexPath *path = [[NSIndexPath alloc] initWithIndexes:indices length:2];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:path] withRowAnimation:UITableViewRowAnimationNone];
[path release];
download.delegate = nil;
}


All I do here is figure out the index of the object that I've been notified has finished download and I build an index path based on it. I then tell the table to reload that one cell's row. Doing that will trigger tableView:cellForRowAtIndexPath: to get called again for the row that has completed and this time that method will get a valid image and will stop the activity indicator and show the downloaded image instead.

Ta da! That's it. It's really not any harder than using threads or NSOperationQueue once you get a feel for using the run-loop based approach.

If you want to try it out, you can download the full project right here. As always, the code is free for use without any restrictions or limitations, I'd just ask that you don't republish it unchanged and claim credit for it.

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Lady Gaga, Salman Khan