iPhone Game Development - Chris Craft [83]
FIGURE 6.21
The select framework folder screen that appears after choosing Add⇒Existing Framework
Because some of the source code for the Facebook Connect for iPhone is stored outside of your Facebook application, you will need to add the path for this code to your Facebook project. To do this, choose Project⇒Edit Project Settings. This brings up the screen shown in Figure 6.22.
FIGURE 6.22
Project settings screen
There are lots of project settings, but we are only interested in one of them, Header Search Paths. You could either find this setting yourself through manual searching, or you can enter it in the filter at the top of the screen. Once you locate this setting, double-click in the cell to the right of the field to open the Header Search Paths screen (Figure 6.23). Click the small plus sign located in the bottom-left corner of the form to add a new header search path. Then double-click the cell under the path column to enter the new header search path. If you have spaces in your path, be sure to enclose your path inside double quotes, as we've done in the previous sentence. This will keep Xcode from reading your path as a list of paths separated by spaces.
FIGURE 6.23
Header Search Paths screen
If you build your Facebook application now, you should see the Build succeeded message in the Xcode bottom Status Bar.
Working with sessions
Now you will work on making your Facebook project a more functional application. The FBSession object is the key component in the FBConnect API. This object contains a user's authorization and login information. The FBSession object requires you to provide your Facebook application's API key and application secret:
session = [FBSession sessionForApplication: @” Find the MainViewController.m file in your Xcode project in the Groups & Files list. It is under the Facebook folder, and then inside the Main View folder. Look in this file for the following code: /* If you need to do additional setup after loading the view, override viewDidLoad. - (void)viewDidLoad { } */ You need to uncomment (by removing the leading forward slash) this section of code so that Xcode compiles it into your application and runs any code you add inside of the viewDidLoad method. Add the FBConnect session line of code you saw in the preceding code listing. Your viewDidLoad method should now match this code listing: - (void)viewDidLoad { session = [FBSession sessionForApplication: @” } This one piece of code will actually be the plumbing that allows your application and Facebook to communicate with each other. But in order for this plumbing to work smoothly, you still have some work to do. Just like with the Facebook-supplied sample, you need to replace the API key and application secret with yours. You also need to include the FBConnect.h header file using the following line of code. Add this import statement at the top of the MainViewController.m file under the existing import statements: #import “FBConnect/FBConnect.h” By adding this, Xcode will understand what the FBSession object is and does. That enables the FBSession object and its sessionForApplication method. In the previous block of code, notice at the end of the main line of code that you set the sessionForApplication's delegate to self. By doing this you are telling Xcode that this class will be responsible for handling any of the needs of the sessionForApplication method. Learning more about delegates and protocols Here is a great way to learn what a class will have to implement in order to meet a delegate's requirements. A delegate is a way