Online Book Reader

Home Category

iPhone Game Development - Chris Craft [87]

By Root 1602 0
learn how to set your application's background to the color of your choosing. In Xcode, find the Groups & Files listing, and then locate the Resources folder under the Facebook project. Click on this folder to expand it and find the MainView.xib file.

FIGURE 6.26

Facebook Connect login


Double-click on this file to open it in Interface Builder. Click in the Main View window, and then choose Tools⇒Inspector. Click on the first tab labeled Main View Attributes, and click on the Background color picker. The Colors dialog box appears, as shown in Figure 6.27, and you can choose whichever background color you like. If you want it to match the Facebook Connect sample, set the background color to turquoise.

FIGURE 6.27

Setting the background color


You don't have to use the FBLoginButton to allow users to connect to Facebook. You can force the Facebook Connect login dialog box to show manually by calling the following code:

FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:session] autorelease];[dialog show];

The FBLoginDialog works very similarly to the UIAlertView that you learned about earlier in the chapter. Once the user has successfully logged in, the session object passed to initWithSession will have a valid session key from Facebook. One good feature that you get for free by using the FBLoginButton is that it automatically becomes a Logout button once the user has logged in.

Whether you allow users to log in to Facebook using the FBLoginButton or the FBLoginDialog in your Facebook application, once the user has logged in successfully, the didLogin method you created is fired and the user sees the screen shown in Figure 6.28.

FIGURE 6.28

The Oh Yeah! screen


If the user checks the Keep me logged in check box in the Connect to Facebook dialog box, the session never expires. By default, the session object expires after two hours. The FBSession object stores the session information in your application's preferences so that it can be reused later automatically.

The FBSession object has a special method named resume, which you can call to automatically resume a previous session if it is still valid. Update your viewDidLoad method to match the following code listing to enable this functionality:

- (void)viewDidLoad

{

[session resume];

session = [[FBSession sessionForApplication:@”” secret:@” ” delegate:self] retain];

FBLoginButton* button = [[[FBLoginButton alloc] init] autorelease];

button.style = FBLoginButtonStyleWide;

[self.view addSubview:button];

}

The resume method returns a YES or a NO, depending on whether it found an active session, which you can use to customize your application to the current situation. The FBLoginButton is session aware. If the resume method is able to restore an active session, the FBLoginButton works as a Logout button; otherwise, it functions as a Login button.

The FBLoginButton can automatically handle the details of logging out the user, or you can programmatically do this yourself by calling the following code:

[session logout];

Getting extended permissions

You are able to access many of the Facebook API calls from your application once you have an active session. But as we mentioned earlier in the chapter, some actions require additional permission before the Facebook Connect API allows your application to perform them. These actions require the user to directly give you explicit permission to perform them. Some examples of tasks that require extended permissions are updating the user's status, sending the user e-mail, or accessing the user's information when the user isn't logged in to your application. To ask your users for extended permission, you need to call FBPermissionDialog.

The following code listing shows how to create an FBPermissionDialog that requests permission from the user to update his Facebook status, as shown in Figure 6.29:

FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];

dialog.delegate = self;

dialog.permission = @

Return Main Page Previous Page Next Page

®Online Book Reader