Online Book Reader

Home Category

iPhone Game Development - Chris Craft [85]

By Root 1541 0
a new import statement to the MainViewController.h file. This instructs the compiler where to search to learn what makes the FBSessionDelegate work.

By adding the FBSessionDelegate to your MainViewController.h file, you are promising the compiler that it will be able to find any methods required by the FBSessionDelegate in your MainViewController.m file. That means at a minimum you will need to implement the didLogin method of the FBSessionDelegate in your MainViewController.m file.

Creating alert views

Add the following didLogin method to your MainViewController class. This code displays an alert view to the user when the application is able to log in to Facebook Connect. The alert view displays the text “Oh Yeah!” and waits for the user to click the OK button to close the dialog box:

////////////////////////////////////////////////////////////////////////////////

// FBSessionDelegate

- (void)session:(FBSession*)session didLogin:(FBUID)uid

{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@”Oh Yeah!” delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil];

[alert show];

[alert release];

}

Take a moment to examine the code for the UIAlertView. One way to learn more about a class in Xcode is to right-click on it, and chose Find Selected Text in API Reference.

Note

You will likely create many alert view dialog boxes in your iPhone applications. They are a great way to present information to users.

Do this now for the UIAlertView. You can now read through the official API Reference documentation, as shown in Figure 6.24. Here you can find much more detailed information about the selected object:

The Overview section offers a quick synopsis of the object's function and features.

The Tasks section highlights the most common tasks for that object.

The Properties section gives you a detailed listing of all properties and methods with full explanations of how each one works.

We recommend referring to the official API Reference frequently. You will learn more about Objective-C and iPhone programming every time you do so.

Did you notice that the UIAlertView has a delegate of its own? This delegate gives you a way to be notified when the user responds to the alert view by clicking one of its buttons. You could learn more about this delegate by choosing Jump to Definition on the UIAlertView, or you could look it up in the API Reference documentation by choosing Find Selected Text in API Reference. Either way, you will learn that the UIAlertView implements the UIAlertViewDelegate, and that all of its methods are marked optional. The default behavior of the alert view is to close the view when the user clicks the Cancel button, but you can optionally implement the alertViewCancel method and respond as needed.

FIGURE 6.24

API Reference window


Xcode has another useful tool for finding more information about the code you are writing. It is called the Research Assistant. You can enable the Research Assistant by choosing Help⇒Show Research Assistant. You can also use the keyboard shortcut Ctrl+Command+?. You can see the Research Assistant window in Figure 6.25.

The Research Assistant provides real-time, context-sensitive help. This means that as you type, the Research Assistant shows information related to what you have just typed. It contains the following types of related information: a simple abstract, availability of the feature, related APIs, related documents, and even links to sample code. There is no question that the Research Assistant feature of Xcode can help you learn more and do more in less time. And it's easier than trying to learn everything on your own.

FIGURE 6.25

Research Assistant window


Now you should be able to build your project without any warnings related to FBSessionDelegate. But you will get a warning related to using an undeclared variable named session:

Error: ‘session' undeclared (first use in this function)

That is because back when you wrote your line of code to assign the FBSession object to your session object,

Return Main Page Previous Page Next Page

®Online Book Reader