<?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>Digicorp &#187; facebook</title>
	<atom:link href="http://dev.digi-corp.com/category/facebook/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.digi-corp.com</link>
	<description>&#62;&#62; Developer Blog</description>
	<lastBuildDate>Wed, 22 Jun 2011 14:13:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google Map, Camera, iPod Library and Facebook Connect with iPhone</title>
		<link>http://dev.digi-corp.com/2009/09/google-map-camera-ipod-library-and-facebook-connect-with-iphone/</link>
		<comments>http://dev.digi-corp.com/2009/09/google-map-camera-ipod-library-and-facebook-connect-with-iphone/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 07:45:41 +0000</pubDate>
		<dc:creator>pratik.joshi</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Camera]]></category>
		<category><![CDATA[Encoding Image]]></category>
		<category><![CDATA[Facebook Connect]]></category>
		<category><![CDATA[Google Map]]></category>
		<category><![CDATA[iPod Library]]></category>
		<category><![CDATA[MKMapView]]></category>
		<category><![CDATA[MKUserLocation]]></category>

		<guid isPermaLink="false">http://dev.digi-corp.com/?p=1275</guid>
		<description><![CDATA[Displaying Google map The iPhone SDK 3.0 offers a class of map view in MapKit framework. You just need to declare an object of MKMapView and add it to your current view. MKMapView *mapview=[[MKMapView alloc]initWithFrame:(CGRectMake(0, -20, 320, 320))]; [self.view addSubview:mapview]; Now, to display the user location on map, I was trying to insert a pin [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1350" src="http://dev.digi-corp.com/wp-content/uploads/2009/08/iphone_home.gif" alt="iphone_home" width="300" height="495" /></p>
<p><strong>Displaying Google map</strong></p>
<p>The iPhone SDK 3.0 offers a class of map view in MapKit framework. You just need to declare an object of MKMapView and add it to your current view.</p>
<p style="padding-left: 30px;"><span style="color: #993300">MKMapView *mapview=[[MKMapView alloc]initWithFrame:(CGRectMake(0, -20, 320, 320))];</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">[self.view addSubview:mapview];</span></p>
<p>Now, to display the user location on map, I was trying to insert a pin annotation on map. Soon, I realized that was wrong approach. User location is meant for changing. It will be updated many time.</p>
<p>The solution for this was to use the MKUserLocation class object. The object of this class will return “Blue dot” of built-in Google map application on iPhone. It will also show animated circle with radius of probable range of user location.</p>
<p style="padding-left: 30px;"><span style="color: #993300">MKUserLocation *ulocation=[[MKUserLocation alloc]init];</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">[mapview setShowsUserLocation:TRUE];</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">[mapview addAnnotation:ulocation];</span></p>
<p>That&#8217;s it. You don&#8217;t need to worry any more about the current location of user. The ulocation object will change its co-ordinates and display the dot whenever the position is updated.</p>
<p><img class="alignnone size-full wp-image-1348" src="http://dev.digi-corp.com/wp-content/uploads/2009/08/iPhoneMap.png" alt="iPhoneMap" width="470" height="254" /></p>
<p><strong>Sending encoded image</strong></p>
<p>You can send images to web service either by mail or by encoding it to string. I have used base64 encoding method to encrypt the image taken from iPhone camera and to send it to web service.</p>
<p>Generally, the image taken from iPhone camera is of very large size (800 kb to 2 mb). So, it may take very long time to encode the image.</p>
<p>I found another way to do the same thing. After taking the picture, you can display the image taken in full view of screen (320*480). Then take the screenshot at that stage and fetch the new image for encoding. In this way, you can make your encoding faster as this was the same picture taken using camera.</p>
<p>I have used following process to take the screenshot.</p>
<p style="padding-left: 30px;"><span style="color: #993300">UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">UIGraphicsBeginImageContext(screenWindow.frame.size);</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">UIGraphicsEndImageContext();</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">NSData *screenshotPNG = UIImagePNGRepresentation(screenshot);</span></p>
<p>Now, since you have the image in screenshotPNG, you can encode it using your base64 method.</p>
<p style="padding-left: 30px;"><span style="color: #993300">NSString *dstring=[[NSString alloc]init];</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">dstring=[self base64StringFromData:screenshotPNG length:[screenshotPNG length]];</span></p>
<p><strong> </strong></p>
<p><strong>Playing a specific song</strong></p>
<p>With iPhone SDK 3.0, we have the access to iPod library on iPhone. The apple documentation “<a href="http://developer.apple.com/iphone/library/documentation/Audio/Conceptual/iPodLibraryAccess_Guide/Introduction/Introduction.html">iPodLibraryAccess Guide</a>” covers most of the part needed for understanding this functionality. Here, I will describe how to play a specific song stored on iPhone.</p>
<p>Let&#8217;s assume our song name is in songtitle which is NSString. To begin, we need objects of</p>
<p style="padding-left: 30px;"><span style="color: #993300">MPMusicPlayerController and a MPMediaQuery.</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">MPMusicPlayerController* iPodMusicPlayer;</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">MPMediaQuery *everything = [[MPMediaQuery alloc] init];</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">everything=[MPMediaQuery songQuery];</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">NSArray *itemsFromGenericQuery = [everything items];</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">for (MPMediaItem *song in itemsFromGenericQuery)</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">{</span></p>
<p style="padding-left: 60px;"><span style="color: #993300">NSString *mysong = [song valueForProperty: MPMediaItemPropertyTitle];</span></p>
<p style="padding-left: 60px;"><span style="color: #993300">if([mysong isEqualToString:songtitle])</span></p>
<p style="padding-left: 60px;"><span style="color: #993300">{</span></p>
<p style="padding-left: 90px;"><span style="color: #993300">iPodMusicPlayer=[MPMusicPlayerController iPodMusicPlayer];</span></p>
<p style="padding-left: 90px;"><span style="color: #993300">[iPodMusicPlayer setNowPlayingItem:song];</span></p>
<p style="padding-left: 90px;"><span style="color: #993300">[iPodMusicPlayer play];</span></p>
<p style="padding-left: 90px;"><span style="color: #993300">break;</span></p>
<p style="padding-left: 60px;"><span style="color: #993300">}</span></p>
<p style="padding-left: 30px;"><span style="color: #993300">}</span></p>
<p><span style="color: #993300"> </span></p>
<p><strong>Using Facebook Connect on iPhone</strong></p>
<p><a href="http://wiki.developers.facebook.com/index.php/Facebook_Connect_for_iPhone">Facebook Connect </a>used in iPhone lets user connect to their facebook account. I am facing one problem in maintaining session of facebook. The sample application provided with facebook sdk allows user to stay logged-in even if iPhone application is terminated. So, the user will not have to enter facebook account username and password next time.</p>
<p>We can know the status of user if he is logged in by using -</p>
<p style="padding-left: 30px;"><span style="color: #993366;">(void)dialogDidSucceed:(NSURL*)url  and – (void)sessionDidLogout:(FBSession*)session method from FBLoginDialog.m.</span></p>
<p>Whenever user logsin using facebook account, the session will stored using NSUserDefaults. We can know this by tracking -(void)save; method in FBSession.m file.</p>
<p>The save method in FBSession.m  stores 4 objects in userdefaults: FBUserId, FBSessionKey, FBSessionSecret and FBSessionExpires.</p>
<p>I am facing problem here. Whenever I try to resume previous session, using -(BOOL)resume; method in FBSession.m, I get correct userid, but rest of the values will be nil. i.e.session key, sesison secret and session expirary date are nil. So, I get one fatal error at that time saying: “attempt to insert nil value (key: session_key)”  I am still trying to find out the solution for that.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.digi-corp.com/2009/09/google-map-camera-ipod-library-and-facebook-connect-with-iphone/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

