Social Icons

twitterfacebookgoogle pluslinkedinrss feedemail
Showing posts with label Programming Tutorials. Show all posts
Showing posts with label Programming Tutorials. Show all posts

Monday, August 27, 2012

A Beginner's Tutorial on String Comparison in C#

Usually in our applications when we want to compare two strings we use the equality operator. Under most scenarios this will work properly but still we should know what are the other ways we can do string comparisons and perhaps achieve better performance and results. So lets say I have a variable str and I want to check whether its value is equal to "Yes" or not.

Read More...

I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


This article is related to

C#,.NET,Architect,Intermediate,Computer Tips and Tricks,Computer Tutorials,Dot Net Interview Questions,Interview Questions,Programming Tutorials,Sample Code,String,Beginner

Step by Step Creating UserControl : DataGridView With Paging

I have Created this UserControl for those who are looking for DataGridView paging functionality. So many times we are using DataGridView in our Windows application with paging. So my intention for this article is to show User Control creation and To provide DataGridView with paging functionality.

Although Creating paging functionality is very basic. but i want to show you features of UserControls through this article and i think this would be the best topic to learn user control. People already know about DataGridView and Paging so there won't be any additional knowledge required to understand the functionality.

Read More....


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


This article is related to

C#,.NET,Architect,Intermediate,Computer Tutorials,Programming Tutorials,Sample Code,SilverLight,SilverLight Tutorial,WPF,LINQ,XAML,C# 4.0

Tuesday, July 17, 2012

Positioning Popup Menus in Windows 8 Metro

Often when building Windows 8 apps you'll want to provide a menu of options from the app bar, this may be a list of different ways to sort or filter the data. For these simple menus WinRT provides the PopupMenu control (for more complicated popup user interfaces I recommend the Flyout control from the Callisto library), these menus are very easy to create by creating UI Commands and appending them to the menus Commands collection.

Read More from: Original Source


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


This article is related to

C#,.NET,Intermediate,Advanced,Articles,Computer Tips and Tricks,Computer Tutorials,Metro Style Applications,Microsoft,Operating Systems,Programming Tutorials,Window,Windows 8

Ultimate WP About Dialog

What does your app say about you as a developer? The app about page establishes your reputation in the eyes of the app user. It is as important as your interview attire. As you wouldn't wear flip-flops to an interview, you would also not want to have a poorly designed about page in your app.

About page is a great way to show your professionalism in a pretty and engaging way. Furthermore, It also provides an opportunity for you to advertise your other apps.

Read More from: Original Source


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


This article is related to

C#,.NET,Intermediate,Advanced,Articles,Computer Tutorials,MMicrosoft,Mobile Development Tutorials,Mobile Developments,Programming Tutorials,Sample Code,Visual Studio,Window,Window Phone Tutorials,WP7,WP8,WPF,XAML

Tuesday, July 3, 2012

XAML binding resources from a separate assembly

Following the session that Glenn (twitter) and I presented at Community Day 2012 as members of the Belgian Windows Phone User Group, we're writing a couple of posts explaining the topics and showing some code.

In this post we're handling the use of resources in your Windows 8 Metro application. As your Windows 8 application can be made available word-wide through the marketplace, there's no discussion that you should localize the app to target this global market.

Read More from: Original Source


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too. 

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


Thursday, June 28, 2012

Windows 8 XAML Tips - Show a task pane

You can integrate the look and feel introduced in Windows 8 Release Preview into your Metro style app by using the Animation Library suite of Windows-provided animations. Use of the Animation Library animations provides these benefits:

Motions that align to Metro style animation principles
Fast, fluid transitions between UI states that inform but do not distract the user
Clearer visuals to show the user transitions within an app

Read More from: Original Source


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too. 

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


Wednesday, June 27, 2012

How to consume WCF SOAP Service in C#/XAML based Metro Application

In this post we will consume WCF SOAP Service in C#/XAML based Metro Application. This is level 100 post showing basic steps to create simple WCF Service and consume that in Metro Application.

Very first let us create a WCF Service using VS2012. Form File menu create a new project by choosing WCF Service Application project template from WCF tab.

Read More...


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too. 

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


Monday, June 25, 2012

Windows 8: 15 More Reasons why I choose XAML over HTML5

Metro developers building applications for Windows 8 have choices to make. A few weeks ago, I put together my top ten reasons to choose XAML. That really got me thinking. There are so many more than 10 good reasons why I prefer XAML. I thought I would continue the list.

Read More from: Original Source


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too. 

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


Mixing themes in XAML Metro apps

For Metro-style apps created using XAML, Windows 8 SDK provides three predefined themes - light, dark and high contrast. Two of three themes – light and dark - can be selected programmatically by assigning Application.RequestedTheme property.

Read More from: Original Source

I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too. 

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


Thursday, June 21, 2012

What's New & Awesome in Telerik XAML Q2 2012

In this webinar, you will learn about everything new in RadControls for Silverlight, WPF, and Windows Phone. We will start with Silverlight/WPF and discuss rich data visualization with the help of controls such as Diagrams, GanttView, and HeatMap. After that we will switch gears and discuss new Windows Phone 7 controls as well as our new Metro design templates created by our designers and implemented by developers (like you!). You'll leave this webinar understanding what the added value Telerik brings to your next XAML Line-of-Business or Windows Phone application.

Read More from: Original Source


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too. 

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


Sunday, June 17, 2012

The Best iOS 6 Features Nobody Is Talking About (Updated)

The keynote on Monday covered 10 new features of iOS 6, but those are, of course, just a small fraction of the 200 new features that this update will offer. A blog post on Gizmodo has collected 10 (and counting) of the coolest new features that weren't mentioned on Monday, and the blog comments are highlighting even more. If you use the Clock app as an alarm, with iOS 6 you'll be able to select any song on your iPhone or iPad to serve as the alarm. In addition, the iPad has a new Clock app. Also of note are new App Store and iTunes Store apps that are more attractive and easier to navigate. And an important addition is a new item in settings that lets you conrol the privacy settings for all of the apps that have asked your permission to access location, contacts, calendars, reminders, and photos. 


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too. 

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


Apple introduces iOS 6, available this fall

Apple introduced iOS 6 now, with 200 new features. It will be available this fall for the iPhone 3GS and later, the iPad 2 and 3, and the fourth generation iPod touch. Ten of the new features were demoed, and they all look pretty exciting. The changes to Siri seem the most remarkable. You can now ask Siri specific questions related to sports (scores, stats, standings, etc.), restaurants (nearby restaurants, maps, hours, prices, reviews -- even make reservations), and movies (reviews, locations and times -- and even view the trailer right within Siri). You'll also be able to use Siri to launch apps, and in the coming year auto manufacturers will begin building a Siri button into the steering wheel such that you can interact with Siri just by touching the button. Siri also will now be available on the new iPad.

Siri will also be deeply integrated with the new Maps app. You'll just tell Siri where you want to go, and you'll get turn-by-turn directions as you drive. And it's all done in real-time, such that Siri might dynamically change your route based on traffic conditions.

And speaking of Maps, that may be the most significant new app introduced. Apple has rewritten it from the ground up, even doing their own cartography. As was rumored, there's a 3-D vector-based maps view. The app now includes local search, and a Flyover mode, as well as a satellite view. 

Another significant new app is Passbook. It unifies all the passes you might have: movie theaters, airline tickets, App Store gift cards. That way, you don't have to fumble among apps on your device. You just go to Passbook and it automatically shows you the one that you need. Apple gave the example of your movie theater pass automatically popping up as you enter the theater. And regarding your airline tickets, they dynamically update if there are changes to your flight.

As was rumored, there will now be deep Facebook integration. You simply log into Facebook in your settings, and then you're automatcially logged in for any app that accesses your Facebook account. Things such as Facebook contact info and events are integrated with your contacts and calendar in iOS.

The Phone app has some highly useful new features, such as options for responding to a call from the lockscreen, and automatically sending a pre-made text message saying things such as "I'm in a meeting and will call you when I get home." A Do Not Disturb feature lets you get a call but without your device lighting up or making a sound. You'll now also have greater control over what calls come through, such as no calls, or only calls from favorites or a particular group.

A neat new feature of Safari is iCloud tabs. If you have tabs open on your desktop computer, you can choose to see those same tabs in Safari on your device. Other features including uploading photos directly from Safari, an offline reading list, and smart app banners. If you go to a web site that has an app in the App Store, you'll receive an alert that the app is available. Then when you download and open the app, it will pick up right where you left off in your browser.

The big news for Facetime in iOS 6 is that it will now work over the cell phone data network, and not just via WiFi. Also, Apple is now integrating a unified ID, such that if you get a call on your device, you can answer it via your Mac or iPad. iMessage will have the same integration.

Mail has some new features too, including a VIP feature. If one of your VIPs emails you, you can receive an alert in your lockscreen. And there's a special mailbox for VIP email. 

Guided Access is a new app that lets you control what your device shows. You can lock it so that it only accesses a specific app, for example. If you're a teacher giving a test, you'll be able to disallow your students from doing anything else on their iPad while taking the test.

Photostream's update will now let you share selected photos from your Photostream.


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too. 

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


Saturday, May 14, 2011

Reading Harddisk Information Using Silverlight 4 Out Of Browser Application

To read the hard disk information in silverlight was my question which I have search on net and was keen to do that, because I want to learn the silverlight. So after search on internet and searching the msdn for this question here is what I have found. You can see the out of the sample code in the Image 1, Here in the Image 1 I have display the hard disk partition just like the window 7 , the title , the progress bar to indicate the usage of the partition space and the at the end the summary of the the partition size.
Image 1
Now let us start with the code sample. First you have to create silverlight out of browser application for this you can click here to read how to create an out of browser application. From the link you can learn how to create an out of browser application in detail.Below is my code which is used to get the drive information. Here you can see that I have called the AutomationFactory.CreateObject, and passing the progID to the CreateObject.The AutomationFactory Provides access to registered Automation servers.Automation is a Windows-based technology that applications use to expose functionality to scripting tools and other applications. For example, you can use Automation to add Office features to your Silverlight-based applications.
An application or component exposing functionality is called an Automation server; an application accessing the functionality is called an Automation client. Because Automation servers must be preinstalled and run in full trust, Silverlight enables only trusted applications to serve as Automation clients.
dynamic fileSystem = AutomationFactory.CreateObject("Scripting.FileSystemObject");
dynamic drives = fileSystem.Drives;
DriveInformationCollection = new List≶DriveInformation>();

foreach (var drive in drives)
{
try
{
if (drive.IsReady)
DriveInformationCollection.Add(new DriveInformation
{
VolumeName = drive.VolumeName,
DriveLetter = drive.DriveLetter,
TotalSpace = drive.TotalSize,
FreeSpace = drive.FreeSpace,
FileSystem = drive.FileSystem,
DriveType = (eDriveType)Enum.ToObject(typeof(eDriveType), drive.DriveType)
});
}
catch (COMException Ex)
{
string strMessage = Ex.Message;
}
}
Now we have the reference of the automation server which is store in fileSystem of type dynamic.Dynamic is a new type provided by framework 4, you can get more information about the dynamic type by clicking here. Next I have call the drives object of the fileSystem to store the drive in new dynamic object. And then I have used to foreach loop to get the drive information to be store in the class which I have created with the name DriveInformation name.The Drive object allows you to gain information about the various drives attached to a system, either physically or over a network. Its properties allow you to obtain information about:
  • The total size of the drive in bytes (TotalSize property)
  • How much space is available on the drive in bytes (AvailableSpace or FreeSpace properties)
  • What letter is assigned to the drive (DriveLetter property)
  • What type of drive it is, such as removable, fixed, network, CD-ROM, or RAM disk (DriveType property)
  • The drive's serial number (SerialNumber property)
  • The type of file system the drive uses, such as FAT, FAT32, NTFS, and so forth (FileSystem property)
  • Whether a drive is available for use (IsReady property)
  • The name of the share and/or volume (ShareName and VolumeName properties)
  • The path or root folder of the drive (Path and RootFolder properties)
In the view of the form. I have used the list box control to display the drive information , which consist of the text block and the progress bar control.For progress bar control I have added two ChangePropertyAction. The condition for first ChangePropertyAction is to check the value of the progress bar if the value is greater then or equal to 80 then the progress bar will be shown red and if the value of the progress bar is less then 80 then progress bar will be shown normally. And the bottom of the user control I have used the grid layout control, the data context of the grid control is set to the selected Item of the list box control. When the selection of the list box changed the correspondent detail of the selected item will be displayed at the bottom of the user control.

References 

1- Automation Class

2- Working with Drives and Folders

Changing Background Color Of DataGrid Cell WPF 4

In this short post I will show you how to change the background color of the column of the data grid control depending on the binding value.Let us start with the code what code or technique you need to change the background color of the column of the data grid control.The output of the example code can be see in Image 1. Here you can see that I have set background of the column to green and red which has values 80 and 90 respectively. Now I will explain you the code which is used to set the background of the column.
 
In the List 1 you can see the xaml code which is used to set the background color of the column of the data grid control, depending on the value of the binding property.Here you can see that I have used the DataGridTemplateColumn and set the header and the sortMemberPath ( used to sort the column, if not given you can't sort the DataGridTemplateColumn). And then I have used the CellTemplate to define the DataTemplate of the column. As I have only one property to be bind in this column so I have place border control and then inside the border control I have place the text block control and bind the text property of the text block control.
 <DataGridTemplateColumn Header="Total Sale in %" SortMemberPath="Sales">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<Border x:Name="brdBroder" VerticalAlignment="Stretch" Margin="1">
<TextBlock Text="{Binding Sales}" Margin="3,1" x:Name="txtTextBlock"/>
</Border>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Sales}" Value="80">
<Setter TargetName="brdBroder" Property="Background" Value="Green"/>
<Setter TargetName="txtTextBlock" Property="Foreground" Value="White"/>
</DataTrigger>
<DataTrigger Binding="{Binding Sales}" Value="90">
<Setter TargetName="brdBroder" Property="Background" Value="Red"/>
<Setter TargetName="txtTextBlock" Property="Foreground" Value="White"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

Next is to define the trigger which are used to change the background color of the border which is placed in the Data Template. Here I have used the DataTrigger, which will used to check the value of 80 and 90 and set the background color of the border control to the green and red respectively as you can see in the Image 1 which is shown at the start of the post

Saturday, April 9, 2011

iPhone Tutorials

iPhone Tutorials

This site contains a ton of fun tutorials – so many that they were becoming hard to find! So I put together this little page to help everyone quickly find the tutorial they’re looking for. Hope you enjoy! :]



Beginning iPhone Programming

iPhone programming is like a ladybug - fun and only a little scary!
iPhone programming is like a ladybug - fun and only a little scary!
If you’re completely new to iPhone programming, start here! First there’s a tutorial series that will walk you through the process of creating an iPhone app from start to finish – using the most common APIs that almost every app uses. Next there’s a tutorial about memory management – the area where beginners most often get confused about!




Game Programming with Cocos2D, Box2D, and Chipmunk

Ninjas Going Pew-Pew!
Ninjas Going Pew-Pew!
If you want to make games on the iPhone, the easiest way by far is to use the Cocos2D iPhone framework and the physics libraries that come with it – Box2D and Chipmunk. These tutorials will help get you started by showing you how to make some simple games and solve common problems.
In addition to these tutorials, you might be interested in the Cocos2D book Rod Strougo and I are working on.




Game Programming and Development

Tomato-San says: w00t, it's done!
Tomato-San says: w00t, it's done!
While we’re on the topic of game programming, here are a few posts with some tips and tricks for game developers.




Saving and Loading Data

Core Data Failed Banks Model Diagram
Core Data Failed Banks Model Diagram
Almost every app needs to save and load data on the iPhone – and there are many different ways to do so. In these tutorials, you can get hands-on experience with many of the most common methods.




Graphics and Animation

Welcome to Core Graphics 101!
Welcome to Core Graphics 101!
In order to be successful on the App Store these days, your app needs to look good. Here are a few tutorials that you can use to up the quality level of your apps, and your gain mad skills with graphics and animation programming.




Audio

Screenshot from BasicSounds sample project
Screenshot from BasicSounds sample project
When I first started iOS programming, I knew a WAV file played sounds and that was about it. These posts explain a lot about audio files and formats, and explain how you can play audio in your apps.




iPad Development

What it will look like when we're done!
What it will look like when we're done!
If you know how to program for the iPhone, it’s a simple matter to program for the iPad as well! These tutorials walk you through some of the differences and help get you started with some of the new APIs available on the iPad.




3rd Party Libraries

I have a soft spot for malteses!
I have a soft spot for malteses!
There are a lot of third party APIs and SDKs you might want to include in your apps. These tutorials cover a few of them and show you how to get started.




Training and Announcements

One day class introducing iOS programming for beginners!
One day class introducing iOS programming for beginners!
From time to time I announce upcoming training, books, and other types of announcements from this site. Here’s the news so far!




Other

1) Integrate iAd 2) ??? 3) PROFIT!
1) Integrate iAd 2) ??? 3) PROFIT!
There’s always something that doesn’t fit anywhere else! Here’s a hodgepodge of other posts and tutorials you may find interesting.

Sunday, February 13, 2011

iPhone FBConnect: Facebook Connect Tutorial

Now a days social networking websites like facebook are becoming very popular, so integrating facebook with app has become a necessity to make you application popular. We are going to do the same through this tutorial. The Facebook Connect SDK provides code which third-party developers can embed into their applications to connect to their Facebook accounts and exchange information with iPhone apps. It’s a way of embedding “social context” to an iPhone app, according to Facebook.
Create a Viewbased Application with name ‘FacebookAPI’.
Prerequisite:
1.Download Facebook Connect for iPhone SDK (http://svn.facebook.com/svnroot/platform/clients/packages/fbconnect-iphone.zip)
Just go through the project. In particular, the “Connect” sample project. Sample Project gives demo of some of the functionality.
1.1.Open src/FBConnect.xcodeproj from SDK that you downloaded, and your own project as well.
1.2.Drag n drop FBConnect group. Make sure “Copy items into destination group folder” is NOT checked. It should look as shown below


1.3.Go to Project Menu ->Edit project settings and scroll down to “User Header Search Path” add entry which will point to “src folder”
1.4.To test import all .m n .h files in case any miss. And compile.
2.Login to Facebook. After that go to Developers Page (http://www.facebook.com/developers/) as shown below.
3.Register your application with Facebook
3.1.Click on Set up New Application Button in the upper right hand corner.
3.2.Give Application name and click on create application button. Then you will see new application screen with detail including “API key”and “API Secret Key”
Note : This application will not work until you provide your Facebook application’s API keys.
Now to get started with actual coding:
Append Following code in

FacebookAPIAppDelegate.h

01#import
02#import "FBConnect/FBConnect.h"
03#import "FBConnect/FBSession.h"
04
05@class FacebookAPIViewController;
06
07@interface FacebookAPIAppDelegate : NSObject  {
08          UIWindow *window;
09          FacebookAPIViewController *viewController;
10          FBSession *_session;
11}
12
13@property (nonatomic, retain) IBOutlet UIWindow *window;
14@property (nonatomic, retain) IBOutlet
15                           FacebookAPIViewController *viewController;
16@property (nonatomic,retain) FBSession *_session;
17@end
Append Following code in FacebookAPIAppDelegate.m

01#import "FacebookAPIAppDelegate.h"
02#import "FacebookAPIViewController.h"
03
04@implementation FacebookAPIAppDelegate
05
06@synthesize window;
07@synthesize viewController;
08@synthesize _session;
09
10- (void)applicationDidFinishLaunching:(UIApplication *)application {
11
12// Override point for customization after app launch
13[window addSubview:viewController.view];
14[window makeKeyAndVisible];
15}
16
17- (void)dealloc {
18          [_session release];
19          [viewController release];
20          [window release];
21          [super dealloc];
22}
23
24@end
Here in FacebookAPIAppDelegate we have just declared _session variable of type FBSession to keep track of the session and to check if session for current user exists or not.
Append Following code in FacebookAPIViewController.h

01#import
02
03#import "FBConnect/FBConnect.h"
04#import "FBConnect/FBSession.h"
05
06@interface FacebookAPIViewController : UIViewController   {
07             FBLoginButton *loginButton;
08             UIAlertView *facebookAlert;
09             FBSession *usersession;
10             NSString *username;
11             BOOL post;
12}
13
14@property(nonatomic,retain) FBLoginButton *loginButton;
15@property(nonatomic,retain) UIAlertView *facebookAlert;
16@property(nonatomic,retain)  FBSession *usersession;
17@property(nonatomic,retain) NSString *username;
18@property(nonatomic,assign) BOOL post;
19
20- (BOOL)textFieldShouldReturn:(UITextField *)textField;
21-(void)getFacebookName;
22-(void)postToWall;
23
24@end
Append Following code in FacebookAPIViewController.m

01#import "FacebookAPIViewController.h"
02#import "FacebookAPIAppDelegate.h"
03
04#define _APP_KEY @"Your API Key Goes here"
05#define _SECRET_KEY @"Your Secrete Key Goes here"
06
07@implementation FacebookAPIViewController
08@synthesize loginButton;
09@synthesize facebookAlert;
10@synthesize usersession;
11@synthesize username;
12@synthesize post;
13
14- (void)viewDidLoad {
15               FacebookAPIAppDelegate *appDelegate =
16                          (FacebookAPIAppDelegate *)   [[UIApplication
17                                            sharedApplication]delegate];
18                if (appDelegate._session == nil){
19                appDelegate._session = [FBSession
20                                   sessionForApplication:_APP_KEY
21                                   secret:_SECRET_KEY delegate:self];
22                 }
23                 if(self.loginButton == NULL)
24                 self.loginButton = [[[FBLoginButton alloc] init] autorelease];
25                 loginButton.frame = CGRectMake(0, 0, 100, 50);
26                 [self.view addSubview:loginButton];
27
28                 [super viewDidLoad];
29}
30
31- (void)dealloc {
32               [username release];
33               [usersession release];
34               [loginButton release];
35               [super dealloc];
36}
37
38- (void)session:(FBSession*)session didLogin:(FBUID)uid {
39                self.usersession =session;
40                NSLog(@"User with id %lld logged in.", uid);
41                [self getFacebookName];
42}
43
44- (void)getFacebookName {
45         NSString* fql = [NSString stringWithFormat:
46         @"select uid,name from user where uid == %lld",
47                               self.usersession.uid];
48        NSDictionary* params =
49        [NSDictionary dictionaryWithObject:fql
50        forKey:@"query"];
51   [[FBRequest requestWithDelegate:self]
52  call:@"facebook.fql.query" params:params];
53   self.post=YES;
54}
55
56- (void)request:(FBRequest*)request didLoad:(id)result {
57              if ([request.method isEqualToString:@"facebook.fql.query"]) {
58                          NSArray* users = result;
59                          NSDictionary* user = [users objectAtIndex:0];
60                          NSString* name = [user objectForKey:@"name"];
61                          self.username = name;
62
63                          if (self.post) {
64                                     [self postToWall];
65                                     self.post = NO;
66                          }
67              }
68}
69
70- (void)postToWall {
71
72               FBStreamDialog *dialog = [[[FBStreamDialog alloc] init]
73                                             autorelease];
74               dialog.userMessagePrompt = @"Enter your message:";
75               dialog.attachment = [NSString
76                    stringWithFormat:@"{\"name\":\"Facebook Connect for
77                    iPhone\",\"href\":\"http://developers.facebook.com/
78                    connect.phptab=iphone\",\"caption\":\"Caption\",
79                    \"description\":\"Description\",\"media\":[{\"type\":
80                    \"image\",\"src\":\"http://img40.yfrog.com/img40/
81                     5914/iphoneconnectbtn.jpg\",\"href\":
82                     \"http://developers.facebook.com/connect.php?
83                      tab=iphone/\"}],\"properties\":{\"another link\":
84                      {\"text\":\"Facebook home page\",\"href\":
85                      \"http://www.facebook.com\"}}}"];
86
87               [dialog show];
88
89}
90
91- (BOOL)textFieldShouldReturn:(UITextField *)textField
92{
93                [textField resignFirstResponder];
94                return YES;
95}
96
97@end
Define API key and Secret key with the keys you received while registering your app on facebook.

1#define _APP_KEY @"43e37a535cc09c2013bd76fde78dfcc7"
2#define _SECRET_KEY @"cc14801521a0c4d1dc31b7cacb891072"
Validate session variable in ViewDidLoad. If it doesn’t exist then create the same for using API key and Secret key. For that, one needs to conform the protocol FBSessionDelegate in respective header file. Also create a login button using FBLoginButton.
While implementing protocol FBSessionDelegate one needs to implement following mandatory method

1(void)session:(FBSession*)session didLogin:(FBUID)uid
This methos is automatically called when user is logged in using FBConnect SDK.
In this method we get session for that user and it’s uid which unique identifier for that user.
Once FBSession session is avaiable, we can accesss all the APIs provided by Facebook.
For now, we will see how to post user name and status on the facebook wall.
To get Facebook username a request is send in which select query is written to get username using uid.

1NSString* fql = [NSString stringWithFormat:
2@"select uid,name from user where uid == %lld", self.usersession.uid];
3NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
4[[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
Override following FBRequestDelegate method to check the reponse of above query.

1(void)request:(FBRequest*)request didLoad:(id)result
The argument result is an array of NSDictionary Objects which contains info for that user as key-value pairs. Retrieve it as follows:

1NSArray* users = result;
2NSDictionary* user = [users objectAtIndex:0];
3NSString* name = [user objectForKey:@"name"];
Use FBStreamDialog class post message on the facbook wall. A dialog pops up with a message box to post on Wall.

1FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
2dialog.userMessagePrompt = @"Enter your message:";
3dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"Facebook Connect for iPhone\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}"];
4[dialog show];
Now Save project (Command +S). Build and Run Project.
Simulator will look like as follows

Click on Fconnect Button and Facebook Login Dialog will appear.

Login with your user name and Password . Wait for untill post to Wall Dialog pops up



You can download the source code from here
There was an error in this gadget
 
Get Twitter Fan Box Widget

Like Us On Facebook and Receive All Updates!

You can also receive Free Email Updates:

Powered By Tutorails

Followers