<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Codrops &#187; iPhone Webapp</title>
	<atom:link href="http://tympanus.net/codrops/tag/iphone/feed/" rel="self" type="application/rss+xml" />
	<link>http://tympanus.net/codrops</link>
	<description>Useful resources and inspiration for creative minds</description>
	<lastBuildDate>Mon, 06 Feb 2012 07:30:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Awesome Mobile Image Gallery Web App</title>
		<link>http://tympanus.net/codrops/2010/05/27/awesome-mobile-image-gallery-web-app/</link>
		<comments>http://tympanus.net/codrops/2010/05/27/awesome-mobile-image-gallery-web-app/#comments</comments>
		<pubDate>Thu, 27 May 2010 09:38:28 +0000</pubDate>
		<dc:creator>Mary Lou</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[iPhone Webapp]]></category>
		<category><![CDATA[jqtouch]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=2204</guid>
		<description><![CDATA[View demoDownload source With more and more users browsing the web with a mobile device, it&#8217;s time to begin with mobile web development. In this tutorial we are going to develop a simple mobile image gallery using the amazing jQTouch jQuery plugin for mobile web development. jQTouch is a jQuery plugin with native animations, automatic [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://tympanus.net/Tutorials/WonderwallMobileGallery/" target="_blank"><img class="aligncenter size-full wp-image-2246" title="mobileimagegallery" src="http://tympanus.net/codrops/wp-content/uploads/2010/05/mobileimagegallery1.jpg" alt="" width="580" height="315" /></a></p>
<p><a class="demo" href="http://tympanus.net/Tutorials/WonderwallMobileGallery/" target="_blank">View demo</a><a class="download" href="http://tympanus.net/Tutorials/WonderwallMobileGallery/WonderwallMobileGallery.zip">Download source</a></p>
<p>With more and more users browsing the web with a mobile device, it&#8217;s time to begin with mobile web development. In this tutorial we are going to develop a simple mobile image gallery using the amazing <a href="http://www.jqtouch.com/" target="_blank">jQTouch</a> jQuery plugin for mobile web development. jQTouch is a jQuery plugin with native animations, automatic navigation, and themes for mobile WebKit browsers like iPhone, iPod Touch, G1, and Pre.</p>
<p><img class="alignright nofancy size-full wp-image-2226" title="splash" src="http://tympanus.net/codrops/wp-content/uploads/2010/05/splash.jpg" alt="" width="215" height="395" /><br />
Our little application is going to show some albums in a list view which will reveal a wall of thumbnails once it&#8217;s clicked. When a thumbnail is clicked, we get to the full image view where we can navigate through all the photos by either clicking on the navigation buttons or swiping over the image.</p>
<p>This app is best viewed on a mobile device like the iPhone or the iPod Touch, or in a Webkit Browser like Google Chrome or Safari. If you are using the iPhone or the iPod Touch (or the iPad), add this app to your home screen to enjoy the full view and features.</p>
<p>Just like in our previous tutorial, the <a href="http://tympanus.net/codrops/2010/05/23/fresh-sliding-thumbnails-gallery-with-jquery-php/" target="_blank">Fresh Sliding Thumbnails Gallery with jQuery and PHP</a> we will be using PHP to automatically generate albums with PHP from the folder structure.</p>
<p>The great thing about jQTouch is that you don&#8217;t really have to worry about much, be it the style or the JavaScript. It has pretty much all the amazing effects that we know from the iPhone as default functionality and it takes care of the right head properties. This makes it really easy to create a mobile device friendly website.</p>
<p>We also have a static version without albums. You can find the demo and the ZIP file at the end of this post.</p>
<p>So, let&#8217;s start!</p>
<div id="bsap_1266918" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div>
<h3>The Markup and JavaScript</h3>
<p>The HTML is pretty simple: for each screen we will have a container that becomes visible when we are on that page.<br />
The first screen that we will have in the HTML is the &#8220;About&#8221; section that get&#8217;s visible when clicking (or tapping) on the about button on the top right:</p>
<pre class="brush:xml">&lt;div id="about" class="selectable"&gt;
	&lt;p&gt;&lt;img src="codropsIcon.png"/&gt;&lt;/p&gt;
	&lt;p&gt;
		&lt;strong&gt;Wonderwall Image Gallery&lt;/strong&gt;
		&lt;a href="http://www.codrops.com"&gt;By Codrops&lt;/a&gt;
	&lt;/p&gt;
	&lt;p&gt;A web app created with &lt;br /&gt; &lt;strong&gt;jQTouch&lt;/strong&gt;&lt;/p&gt;
	&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="#" class="grayButton goback"&gt;Close&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
</pre>
<p><img class="alignleft nofancy size-full wp-image-2209" title="albums" src="http://tympanus.net/codrops/wp-content/uploads/2010/05/albums.jpg" alt="" width="215" height="395" /></p>
<p>The second container that we will have in our HTML structure, will be the part where we dynamically add a list of album links. We get that list automatically from our special folder structure.</p>
<p>The folder structure contains an image folder and a thumbs folder. Each one of those contains folders of albums. They have to be named the same, just like the images inside.</p>
<p>In the thumbnails album folders we will have an XML file called &#8220;desc.xml&#8221; which can be used to write a description for each image. In this file, we will write the name of the picture and it&#8217;s title. The description of each image is not obligatory which means that we can leave out images that don&#8217;t have any title or description.</p>
<p>The structure of that XML file will look as follows:</p>
<pre class="brush:xml">&lt;descriptions&gt;
    &lt;image&gt;
        &lt;name&gt;1.jpg&lt;/name&gt;
        &lt;text&gt;Inna 02 © studio.es by Vincent Boiteau&lt;/text&gt;
    &lt;/image&gt;
    &lt;image&gt;
        &lt;name&gt;2.jpg&lt;/name&gt;
        &lt;text&gt;Inna 01 © studio.es by Vincent Boiteau&lt;/text&gt;
    &lt;/image&gt;
	...
&lt;/decriptions&gt;
</pre>
<p>With the thumbs.php file which we keep in a sub folder called &#8220;ajax&#8221; we will automatically get those descriptions. For a more detailed explanation of the workings, check out our <a href="http://tympanus.net/codrops/2010/05/23/fresh-sliding-thumbnails-gallery-with-jquery-php/" target="_blank">previous tutorial</a>.</p>
<p>The second container&#8217;s HTML structure is going to look like this:</p>
<pre class="brush:xml">&lt;!-- The list of albums --&gt;
&lt;div id="albums_container" class="current"&gt;
	&lt;div class="toolbar"&gt;
		&lt;h1&gt;Albums&lt;/h1&gt;
		&lt;a class="button slideup" id="infoButton" href="#about"&gt;About&lt;/a&gt;
	&lt;/div&gt;
	&lt;div class="loader" style="display:none;"&gt;&lt;/div&gt;
	&lt;ul id="albums" class="edgetoedge" style="display:none;"&gt;
	&lt;/ul&gt;
&lt;/div&gt;
</pre>
<p>The unordered list with the id &#8220;albums&#8221; will be populated with list items containing the links to the albums.<br />
The toolbar will be at the top of the screen and present in every container. It will have a button to get to the about section and a back link that brings us back to the previous screen.<br />
The first step in the JavaScript is to call the function <strong>loadAlbums()</strong> which gets the names of the albums with an AJAX request to the PHP side (albums.php):</p>
<pre class="brush:js">/* name of the selected album */
    var album 				= '';
    /* index of li where there is the selected image */
    var current				= -1;

    /* 1 step : Load the Albums */
    loadAlbums();

    function loadAlbums(){
        var $loader = $('#albums_container').find('.loader');
        $loader.show();
        var url 		= 'ajax/albums.php';
        /*
        gets the names of the albums with an AJAX request to the PHP side
        */
        $.get(url, function(data) {
            $loader.hide();
            $('#albums').html(data).show();
        },'html');
    }

    /*
    clicking on an album:
    we keep track of which album is currently selected by
    getting the id (album name) of the clicked row
    */
    $('#albums_container').delegate('li','click tap',function(e){
        var $this 	= $(this);
        album 		= $this.attr('id');
    });
</pre>
<p>The PHP file albums.php looks as follows:</p>
<pre class="brush:php">&lt;?php
if(file_exists('../images')){
	$files = array_slice(scandir('../images'), 2);
	if(count($files)){
		natcasesort($files);
		foreach($files as $file){
			if($file != '.' &amp;&amp; $file != '..'){
				echo '&lt;li id="'.$file.'" class="arrow"&gt;&lt;a href="#thumbs_container"&gt;'.$file.'&lt;/a&gt;&lt;/li&gt;';
			}
		}
	}
}
?&gt;
</pre>
<p>We are scanning the directory called &#8220;images&#8221; in order to get all the sub folders which are our albums. Note that the each list element link will have a href for the thumbs container. The JavaScript variable &#8220;album&#8221; will keep track of the current album when we click on one of the list items.</p>
<p><img class="alignright nofancy size-full wp-image-2217" title="thumbs" src="http://tympanus.net/codrops/wp-content/uploads/2010/05/thumbs.jpg" alt="" width="215" height="395" /><br />
The third container is the section for the thumbnails. Here we will populate an unordered list #thumbs with the small thumbnail images as link elements.</p>
<p>As you can see in the image, the thumbnails will occupy all the screen. We use a centering function that determines how many thumbnails fit into one row given a certain window width. The left margin is calculated according to the left over space.</p>
<p>We also resize the thumbnails if they are bigger than our predefined width and height of 75px. So, if you use thumbnails that are not quadratic and of different sizes, they will be made to fit into the list element.</p>
<p>The thumbnails view has the following structure:</p>
<pre class="brush:xml">&lt;!-- The list of images (thumbs) --&gt;
&lt;div id="thumbs_container"&gt;
	&lt;div class="toolbar"&gt;
		&lt;h1&gt;Thumbs&lt;/h1&gt;
		&lt;a class="back" href="#albums_container"&gt;Albums&lt;/a&gt;
		&lt;a class="button slideup" id="infoButton" href="#about"&gt;About&lt;/a&gt;
	&lt;/div&gt;
	&lt;div class="loader" style="display:none;"&gt;&lt;/div&gt;
	&lt;ul id="thumbs" class="thumbView" style="display:none;"&gt;
	&lt;/ul&gt;
&lt;/div&gt;
</pre>
<p>In the JavaScript we need to load the thumbnails by making another AJAX request to the PHP side (thumbs.php) which lists us all the images inside of the current album. We also need to keep track of the currently clicked image which we save in the JavaScript variable &#8220;current&#8221;:</p>
<pre class="brush:js">/*
load thumbs when the panel thumbs_container slides in;
hides the thumbs_container when it slides out
*/
$('#thumbs_container').bind('pageAnimationEnd', function(e, info){
	if (info.direction == 'in'){
		loadThumbs();
	}else{
		$('#thumbs').hide();
	}
});

/*
gets the photos information with an AJAX request to the PHP side
then creates and loads each one of the images,
and appends it to the DOM
after that, we need to center the grid of the images
based on how many fit per row
*/
function loadThumbs(){
	var $thumbscontainer = $('#thumbs_container');
	var $loader = $thumbscontainer.find('.loader');
	$loader.show();

	var url = 'ajax/thumbs.php?album='+album;
	$.get(url, function(data) {
		var countImages = data.length;
		var $ul = $('#thumbs').empty();
		var counter = 0;
		for(var i = 0; i &lt; countImages; ++i){
			try{
				var description = data[i].desc[0];
			}catch(e){
				description = '';
			}
			if(description == undefined)
				description = '';
			$('&lt;img alt="'+data[i].alt+'" title="'+description+'"/&gt;').load(function(){
				++counter;
				var $this = $(this);
				/*
				we need to make sure the grid thumbs are no bigger than 75 px
				*/
				resizeGridImage($this);
				var $li = $('&lt;li/&gt;',{
					className	: 'pic'
				});
				var $a = $('&lt;a/&gt;',{
					href	:	'#photo_container'
				});
				$ul.append($li.append($a.append($this)));
				if(counter == countImages){
					$loader.hide();
					$thumbscontainer.append($ul.show());
					autoCenterPhotos();
				}
			}).attr('src',data[i].src);
		}
	},'json');
}

/*
when clicking on an image we keep track of the index
of the image, which is in the alt attribute of the thumb
*/
$('#thumbs_container').delegate('li','click tap',function(){
	current	= $(this).index();
});
</pre>
<p>The thumbs.php looks as follows:</p>
<pre class="brush:php">&lt;?php
	$album 		= $_GET['album'];
	$imagesArr	= array();
	$i			= 0;
	/* read the descriptions xml file */
	if(file_exists('../thumbs/'.$album.'/desc.xml')){
		$xml = simplexml_load_file('../thumbs/'.$album.'/desc.xml');
	}
	if(file_exists('../thumbs/'.$album)){
		$files = array_slice(scandir('../thumbs/'.$album), 2);
		if(count($files)){
			foreach($files as $file){
				if($file != '.' &amp;&amp; $file != '..' &amp;&amp;  $file!='desc.xml'){
					if($xml){
						$desc = $xml-&gt;xpath('image[name="'.$file.'"]/text');
						$description = $desc[0];
						if($description=='')
							$description = '';
					}
					$imagesArr[] = array('src' 	=&gt; 'thumbs/'.$album.'/'.$file,
										 'alt'	=&gt; 'images/'.$album.'/'.$file,
										 'desc'	=&gt; $description);
				}
			}
		}
	}
	$json 		= $imagesArr;
	$encoded 	= json_encode($json);
	echo $encoded;
	unset($encoded);
?&gt;
</pre>
<p><img class="alignleft nofancy size-full wp-image-2222" title="full" src="http://tympanus.net/codrops/wp-content/uploads/2010/05/full.jpg" alt="" width="215" height="395" /><br />
Our last container will be for the full image preview. Here we will use another resize function in order to adapt the width and height of the image to fit into the viewport.</p>
<p>We will also add two navigation buttons that will point to the next and previous images in full preview.</p>
<p>To browse through the images we can either use these navigation buttons or swipe over the image (if our mobile device supports that, i.e. iPhone or iPod Touch).</p>
<p>Between the navigation buttons, we will add the description of the current image.</p>
<p>The resize function that we will be using checks if the image is bigger than the window and if it is, the image gets resized accordingly.</p>
<p>The HTML structure for the last container looks as follows:</p>
<pre class="brush:xml">&lt;!-- The single image container --&gt;
&lt;div id="photo_container"&gt;
	&lt;div class="toolbar"&gt;
		&lt;h1&gt;Photo&lt;/h1&gt;
		&lt;a class="back" href="#thumbs_container"&gt;Photos&lt;/a&gt;
		&lt;a class="button slideup" id="infoButton" href="#about"&gt;About&lt;/a&gt;
	&lt;/div&gt;
	&lt;div class="loader" style="display:none;"&gt;&lt;/div&gt;
	&lt;div id="theimage" class="singleimage"&gt;&lt;/div&gt;
	&lt;div class="descriptionWrapper"&gt;
		&lt;p id="description"&gt;&lt;/p&gt;
		&lt;div id="prev" style="display:none;"&gt;&lt;/div&gt;
		&lt;div id="next" style="display:none;"&gt;&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>And the JavaScript looks as follows:</p>
<pre class="brush:js">/*
    load the large image when the panel photo_container slides in;
    empty the contents of the image element when it slides out
    */
    $('#photo_container').bind('pageAnimationEnd', function(e, info){
        if (info.direction == 'in'){
            var $thumb 		= $('#thumbs_container li:nth-child('+parseInt(current+1)+')').find('img');
            if(!$thumb.length) return;
            loadPhoto($thumb);
        }
        else{
            $('#theimage').empty();
            $('#description').empty();
            $('#prev,#next').hide();
        }
    });

    /* loads a large photo */
    function loadPhoto($thumb){
        var $loader 	= $('#photo_container').find('.loader');
        $loader.show();
        var $theimage 	= $('#theimage');
        $('&lt;img/&gt;').load(function(){
            var $this 	= $(this);
            resize($this);
            $loader.hide();
            var $a=$('&lt;a/&gt;');/*for swipe*/
            $theimage.empty().append($a.append($this));
            $('#description').empty().html($thumb.attr('title'));
            $('#prev,#next').show();
        }).attr('src',$thumb.attr('alt'));
    }

    /* swipe image - navigate right/left */
    $('#theimage').swipe(function(evt, data) {
        if(data.direction=='left')
            navigateNext();
        else
            navigatePrevious();
    });

    /*
    Events for navigating through the images
    The current gives us our current photo,
    so we need to get the next / previous one
    from the thumbs container - these have
    the source for the large photo in the
    alt attribute
    */
    $('#next').bind('click tap',function(){
        navigateNext();
    });
    $('#prev').bind('click tap',function(){
        navigatePrevious();
    });

    /* goes to next image */
    function navigateNext(){
        ++current;
        var $thumb = $('#thumbs_container li:nth-child('+parseInt(current+1)+')').find('img');
        if(!$thumb.length) {
            --current;
            return;
        }
        loadPhoto($thumb);
    }

    /* goes to previous image */
    function navigatePrevious(){
        --current;
        var $thumb = $('#thumbs_container li:nth-child('+parseInt(current+1)+')').find('img');
        if(!$thumb.length) {
            ++current;
            return;
        }
        loadPhoto($thumb);
    }
</pre>
<h4>Initializing jQTouch</h4>
<p>After adding the scripts of jQuery and jQTouch we also have to initialize the jQTouch plugin:</p>
<pre class="brush:js">var jQT = new $.jQTouch({
    icon		: 'codropsIcon.png',
    cacheGetRequests: true,
    addGlossToIcon	: false,
    startupScreen	: 'codropsSplash.png',
    statusBar	: 'black',
    preloadImages: [
        'themes/img/back_button.png',
        'themes/img/back_button_clicked.png',
        'themes/img/button_clicked.png',
        'themes/img/grayButton.png',
        'themes/img/whiteButton.png',
        'themes/img/loading.gif'
    ]
});
</pre>
<p>Beside others, we define the icon for the app and the start up screen image. We can also list what images shall be preloaded. There are several parameters that you can configure. You can find all about the initialization options <a href="http://code.google.com/p/jqtouch/wiki/InitOptions" target="_blank">here</a>.</p>
<p>If we use a device where we can rotate the screen, our image preview will look like this:</p>
<p style="text-align: center;"><img class="nofancy size-full wp-image-2245  aligncenter" title="horizontal" src="http://tympanus.net/codrops/wp-content/uploads/2010/05/horizontal1.jpg" alt="" width="395" height="215" /></p>
<p>And now, let&#8217;s take a look at the style.</p>
<h3>The CSS</h3>
<p>The style for this gallery is mainly based on the provided theme in the jQTouch plugin. We did some minor changes to the colors in the default style and added the following style for the gallery:</p>
<pre class="brush:css">ul.thumbView{
    list-style:none;
    margin:0px;
    border:none;
}
ul.thumbView li {
    float:left;
    position:relative;
    width:80px;
    height:80px;
    border:none;
    margin:0px;
    padding:0px;
    background:transparent;
    line-height:80px;
    overflow:visible;
}
ul.thumbView li a {
    height:80px;
    margin:0;
    padding:0;
    width:80px;
    text-align:center;
    vertical-align:middle;
    display:table-cell;
    overflow:visible;
}
ul.thumbView li a img{
    border:none;
    vertical-align:middle;
    -webkit-box-shadow:2px 2px 8px #000;
}
div.singleimage{
    text-align:center;
    width:100%;
}
div.singleimage img{
    margin-top:10px;
    -webkit-box-shadow:2px 2px 8px #000;
}
.descriptionWrapper{
    height:40px;
    position:relative;
}
p#description{
    text-align:center;
    color:white;
    text-transform:uppercase;
    font-weight:bold;
    margin:10px 0px 0px 0px;
    padding:0px 45px;
}
div#prev,div#next{
    cursor:pointer;
    position:absolute;
    top:10px;
    width:40px;
    height:40px;
    background-color:black;
    background-repeat:no-repeat;
    background-position:center center;
}
div#prev{
    left:0px;
    background-image:url(img/prev.png);
    -webkit-border-top-right-radius:10px;
    -webkit-border-bottom-right-radius:10px;
}
div#next{
    right:0px;
    background-image:url(img/next.png);
    -webkit-border-top-left-radius:10px;
    -webkit-border-bottom-left-radius:10px;
}
div.loader{
    background:transparent url(img/ajax-loader.gif) no-repeat center center;
    position:absolute;
    top:90px;
    width:100%;
    left:0px;
    height:24px;
}
</pre>
<p>And that&#8217;s it! I hope you enjoyed starting with mobile web development!</p>
<p><a class="demo" href="http://tympanus.net/Tutorials/WonderwallMobileGallery/" target="_blank">View demo</a><a class="download" href="http://tympanus.net/Tutorials/WonderwallMobileGallery/WonderwallMobileGallery.zip">Download source</a></p>
<p style="clear: both;">We also have a static version of this mobile photo gallery without the album functionality. Check out the <a href="http://tympanus.net/Tutorials/WonderwallMobileGalleryStatic/" target="_blank">static demo</a> or <a href="http://tympanus.net/Tutorials/WonderwallMobileGalleryStatic/WonderwallMobileGalleryStatic.zip">download the ZIP file</a>.</p>
<div class="googlead"><!-- wp_ad_camp_1 --></div>
<div class="partner_section_post"><span>Message from Testking</span>We offer guaranteed <a href="http://www.pass4sure.com/CCNA-Security.html">ccna security</a> training program to help you pass <a href="http://www.pass4sure.com/CCNA-Voice.html">ccna voice</a> exam on time. Complete your <a href="http://www.pass4sure.com/CCIE.html">ccie certification</a> using certified resources.</div>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2010/05/27/awesome-mobile-image-gallery-web-app/feed/</wfw:commentRss>
		<slash:comments>118</slash:comments>
		</item>
		<item>
		<title>How To Play Looping Sound In Your iPhone App</title>
		<link>http://tympanus.net/codrops/2009/09/15/how-to-play-sound-in-your-iphone-app/</link>
		<comments>http://tympanus.net/codrops/2009/09/15/how-to-play-sound-in-your-iphone-app/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 17:18:30 +0000</pubDate>
		<dc:creator>Mary Lou</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[iPhone Webapp]]></category>
		<category><![CDATA[Looping]]></category>
		<category><![CDATA[Sound]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=480</guid>
		<description><![CDATA[Here is a very useful code snippet for playing your own sound file continuously in your iPhone application. The example uses a .caf file and is based on the AVAudioPlayer Class. You can find the class reference of Apple here: http://developer.apple.com/iPhone/library/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html Let&#8217;s assume that you have a view controller where you want to play some [...]]]></description>
			<content:encoded><![CDATA[<p><!-- google_ad_section_start --><br />
<img class="size-full wp-image-493 alignleft" style="float:left;margin-right:20px;border:none;" title="Playing Sound" src="http://tympanus.net/codrops/wp-content/uploads/2009/09/sound.png" alt="Playing Sound" width="173" height="307" /><br />
Here is a very useful code snippet for playing your own sound file continuously in your iPhone application. The example uses a .caf file and is based on the AVAudioPlayer Class. You can find the class reference of Apple here:<br />
<a href="http://developer.apple.com/iPhone/library/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html" target="_blank">http://developer.apple.com/iPhone/library/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html</a></p>
<p style="text-align: left;">Let&#8217;s assume that you have a view controller where you want to play some sound. I will first start by the header file of your view controller and then move on to the methods in your class MyViewController.m.</p>
<p style="text-align: left;"><span id="more-480"></span></p>
<p style="text-align: left;">In the header file <strong>MyViewController.h</strong> we will define the audio player first:</p>
<pre style="border: 1px solid #ffcc00; color: #000099; background-color: #ffffcc; font-size: 13px; font-family: 'Lucida Console',Monaco,monospace; text-align: left;">#import &lt;UIKit/UIKit.h&gt;

@interface MyViewController : UIViewController {
    AVAudioPlayer *player;
}

@property (nonatomic, retain) AVAudioPlayer *player;

@end</pre>
<p style="text-align: left;">In MyViewController.m we want to load the sound file from our project and allocate the AVAudioPlayer. Further, we will want to define the looping behavior and the volume. This is how we integrate all that in <strong>MyViewController.m</strong>:</p>
<pre style="border: 1px solid #ffcc00; color: #000099; background-color: #ffffcc; font-size: 13px; font-family: 'Lucida Console',Monaco,monospace; text-align: left;">#import "MyViewController.h"

@interface MyViewController()
    -(void)playSound;
@end

@implementation MyViewController

@synthesize player;

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *soundFilePath =
      [[NSBundle mainBundle] pathForResource: @"mySound" ofType: @"caf"];
    NSURL *fileURL =
      [[NSURL alloc] initFileURLWithPath: soundFilePath];
    AVAudioPlayer *newPlayer =
      [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: nil];
    [fileURL release];
    self.player = newPlayer;
    [newPlayer release];
}	

- (void)viewWillAppear:(BOOL)animated{
    player.numberOfLoops = -1;
    player.currentTime = 0;
    player.volume = 1.0;
    [self playSound];
}

- (void)viewWillDisappear:(BOOL)animated{
    if (self.player.playing) {
        [self.player stop];
    }
}

- (void) playSound{
    [self.player play];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
}

- (void)dealloc {
    [super dealloc];
    [player release];
}

@end</pre>
<p style="text-align: left;">Setting <strong>numberOfLoops </strong> to a negative integer will make your sound loop until you call <strong>stop</strong> to terminate the playing of the sound. The <strong>currentTime</strong> is the moment from when you want to play the sound in seconds. So zero means that you want to start from the beginning.<br />
The method <strong>playSound</strong> will call <strong>play</strong> to actually play the sound.</p>
<p style="text-align: left;">Check out the class reference for more options, like pausing your sound or playing more sounds simultaneously.<br />
I hope it helped! Enjoy!</p>
<p><div id="bsap_1266918" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div><br />
<br/><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2009/09/15/how-to-play-sound-in-your-iphone-app/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Checking Network Reachability on the iPhone</title>
		<link>http://tympanus.net/codrops/2009/09/14/checking-network-reachability-iphone/</link>
		<comments>http://tympanus.net/codrops/2009/09/14/checking-network-reachability-iphone/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 21:08:48 +0000</pubDate>
		<dc:creator>Mary Lou</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[iPhone Webapp]]></category>
		<category><![CDATA[network reachability]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=444</guid>
		<description><![CDATA[In some iPhone apps you need to check if there is a connection to the outside world. If the application depends on a connection to the internet, we will want to warn the user of the app, if he cannot connect currently. In programming your app you can for example make sure that a certain [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-475 alignleft" style="float:left;margin-right:20px;" title="No Connection" src="http://tympanus.net/codrops/wp-content/uploads/2009/09/no.png" alt="No Connection" width="173" height="307" />In some iPhone apps you need to check if there is a connection to the outside world. If the application depends on a connection to the internet, we will want to warn the user of the app, if he cannot connect currently. In programming your app you can for example make sure that a certain view is pushed whenever there is no connection available or when your server that you need to connect to is down. When the connection is back up, you can again remove that view or show the default view of your app.</p>
<p>I want to show a simple way how to get notified using the reachability class. If you would like to see how to extensively use the class in a project setting, check out this elaborate tutorial:</p>
<p><a href="http://www.raddonline.com/blogs/geek-journal/iphone-sdk-testing-network-reachability/">http://www.raddonline.com/blogs/geek-journal/iphone-sdk-testing-network-reachability/</a></p>
<p>Here is a checklist for integrating an observer for the connection:</p>
<ol>
<li>Get the Reachability class from Apple, it has all the functionality we need to check if a connection is up/down</li>
<li>Import the class into your app</li>
<li>Initialize it and create an observer</li>
<li>Create a method that handles an alteration of the network status</li>
</ol>
<p><span id="more-444"></span></p>
<p>Basically, we will subscribe to the Notification Center or kNetworkReachabilityChangedNotification which will send us notifications when a change happens. We will handle that change by checking the content of the message sent.</p>
<p>After you get the Reachability class from Apple, import it in your AppDelegate. There we will do our initialization and add an observer. As well, we will put our method there.</p>
<p>So, we are in your <strong>YourAppDelegate.m</strong> and import the Reachability class:</p>
<pre style="color:#000099; background-color:#FFFFCC; border:1px solid #FFCC00;font-size:13px;font-family: 'Lucida Console', Monaco, monospace">#import "Reachability.h"</pre>
<p>In the <strong>applicationDidFinishLaunching </strong>Method we will do the initialization and add an observer:</p>
<pre style="color:#000099; background-color:#FFFFCC;border:1px solid #FFCC00; font-size:13px;font-family: 'Lucida Console', Monaco, monospace">// Set the host name to check:

[[Reachability sharedReachability]
     setHostName:@"www.yourserver.com"]];

// Enable the status notifications:

[Reachability sharedReachability].networkStatusNotificationsEnabled = YES; 

// Add an observer to the notification center and call the method
// handleReachability when there was a notification:

[[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(handleReachability: )
    name:@"kNetworkReachabilityChangedNotification" object:nil];</pre>
<p>I am assuming that you defined some navigation controller and your view controllers. So, we want to get notified whenever the reachability changed. We will call the method <strong>handleReachability</strong> when that happens:</p>
<pre style="color:#000099; background-color:#FFFFCC;border:1px solid #FFCC00; font-size:13px;font-family: 'Lucida Console', Monaco, monospace">-(void)handleReachability:(NSNotificationCenter*)notification{
 if([[Reachability sharedReachability] remoteHostStatus] == NotReachable)
 {
  // what happens when network/server down: 

  [navigationController pushViewController:self.mySecondViewController
   animated:YES];

 }else{

  [navigationController popToViewController:self.myFirstViewController
   animated:YES];

 }
}</pre>
<p>And that&#8217;s it. I hope it helps.<br />
Enjoy!</p>
<p><div id="bsap_1266918" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div><br />
<br/><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2009/09/14/checking-network-reachability-iphone/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>9 Valuable and Working iPhone Programming Tutorials</title>
		<link>http://tympanus.net/codrops/2009/09/03/9-valuable-and-working-iphone-programming-tutorials/</link>
		<comments>http://tympanus.net/codrops/2009/09/03/9-valuable-and-working-iphone-programming-tutorials/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 15:28:54 +0000</pubDate>
		<dc:creator>Mary Lou</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone Webapp]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=210</guid>
		<description><![CDATA[Here is a list of some highly valueable and functioning iPhone programming tutorials (list is open): iPhone View Switching Tutorial iPhone Coding – Learning About UIWebViews by Creating a Web Browser iPhone Dev Sessions: Create a Navigation-Based Application Tutorial: JSON Over HTTP On The iPhone iPhone Programming Tutorial – Creating a ToDo List Using SQLite [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a list of some highly valueable and functioning iPhone programming tutorials (list is open):</p>
<p><strong><a href="http://fuelyourcoding.com/iphone-view-switching-tutorial/" target="_blank">iPhone View Switching Tutorial</a></strong></p>
<p><strong><a href="http://icodeblog.com/2008/12/19/iphone-coding-learning-about-uiwebviews-by-creating-a-web-browser/" target="_blank">iPhone Coding – Learning About UIWebViews by Creating a Web Browser</a><br />
<a href="http://theappleblog.com/2009/04/15/iphone-dev-sessions-create-a-navigation-based-application/" target="_blank"><br />
iPhone Dev Sessions: Create a Navigation-Based Application</a></strong></p>
<p><strong><a href="http://www.mobileorchard.com/tutorial-json-over-http-on-the-iphone/" target="_blank">Tutorial: JSON Over HTTP On The iPhone</a></strong></p>
<p><strong><a href="http://icodeblog.com/2008/09/22/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-4/" target="_blank">iPhone Programming Tutorial – Creating a ToDo List Using SQLite Part 4</a></strong></p>
<p><strong><a href="http://adeem.me/blog/2009/06/24/iphone-programming-tutorial-part-7-adding-pictures-into-your-table-using-interface-builder/" target="_blank">iPhone Programming Tutorial {Part 7}: Adding Pictures into your table using Interface builder</a></strong></p>
<p><strong><a href="http://www.blogcatalog.com/blog/iphone-tutorial-programming-iphone-tutorial-iphone-sdk-tutorial" target="_blank">iPhone Tutorial for Creating a Splash Screen</a><br />
</strong><br />
Send in your suggestions! Which tutorials helped you write your own app?<br />
Enjoy!</p>
<div id="bsap_1266918" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2009/09/03/9-valuable-and-working-iphone-programming-tutorials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript: Changing location or stylesheet according to device or browser</title>
		<link>http://tympanus.net/codrops/2009/08/26/javascript-changing-location-or-stylesheet-according-to-device-or-browser/</link>
		<comments>http://tympanus.net/codrops/2009/08/26/javascript-changing-location-or-stylesheet-according-to-device-or-browser/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 12:58:13 +0000</pubDate>
		<dc:creator>Mary Lou</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone Webapp]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://tympanus.net/bringiton/?p=17</guid>
		<description><![CDATA[Developing web applications for mobile phones sometimes brings the need to just create separate content for different devices.

Some time ago I had to create a web app that would look pretty on both, the iPhone and some Windows Mobile based device by HTC! In the end it came out to be simpler just to create another page for the WM device.

Here is a code snippet that I inserted in the header of the index page of the web app:]]></description>
			<content:encoded><![CDATA[<p>Developing web applications for mobile phones sometimes brings the need to just create separate content for different devices.</p>
<p>Some time ago I had to create a web app that would look pretty on both, the iPhone and some Windows Mobile based device by HTC! In the end it came out to be simpler just to create another page for the WM device.</p>
<p>Here is a code snippet that I inserted in the header of the index page of the web app:</p>
<p><span id="more-17"></span></p>
<pre class="brush: js">&lt;script type="text/javascript"&gt; 

 function browser(){
  var browser = navigator.userAgent;
  //alert(browser);

  //Windows Mobile
  if (browser.match("MDA_compact")|| browser.match("MSIE")) {
    window.location.href = "mda/index.html";
  }
 //iPhone &amp; Rest
  else{
   document.write('&lt;meta name="apple-mobile-web-app-capable" content="yes" /&gt;'
   +'&lt;link rel="apple-touch-icon" href="webapplogo.gif"/&gt;'    
   +'&lt;meta name="apple-mobile-web-app-status-bar-style" content="black" /&gt;'
   +'&lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type" /&gt;'
   +'&lt;meta content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" name="viewport" /&gt;'
   +'&lt;link href="style.css" rel="stylesheet" type="text/css" /&gt;'
   +'&lt;link href="pie.css" rel="stylesheet" type="text/css" /&gt;'
   +'&lt;link href="chart.css" rel="stylesheet" type="text/css" /&gt;'
   +'&lt;link href="messages.css" rel="stylesheet" type="text/css" /&gt;'
   +'&lt;link href="news.css" rel="stylesheet" type="text/css" /&gt;'
   +'&lt;link rel="stylesheet" href="stylesheets/glider.css" type="text/css" media="screen" charset="utf-8"&gt;');   
   }
  }

 browser();

&lt;/script&gt;</pre>
<p>You might want to figure out first, how the target device/browser is called. Uncomment the <span style="color: #008000;">alert(browser)</span> line and get the name. Adapt the <span style="color: #008000;">browser.match(&#8220;Target_browser&#8221;)</span> and define what you want to do in that case, e.g. redirect to another page.</p>
<p><div id="bsap_1266918" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div><br />
<br/><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2009/08/26/javascript-changing-location-or-stylesheet-according-to-device-or-browser/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  tympanus.net/codrops/tag/iphone/feed/ ) in 0.23414 seconds, on Feb 7th, 2012 at 12:24 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 7th, 2012 at 1:24 pm UTC -->
