iPhone Game Development - Chris Craft [82]
- (void)publishFeed:(id)target
{
FBFeedDialog* dialog = [[[FBFeedDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.templateBundleId = 9876543210;
dialog.templateData = @”{\”score\”: \”53324\”, \”rank\”: \”Captain\”}”;
[dialog show];
}
Even though feed templates can be a little tricky to understand at first, they become easier to use with practice, and they are incredibly powerful and flexible. You now have a basic understanding of how all the parts of a Facebook feed template work.
Some actions—like updating the user's status, sending the user e-mail, or publishing information to a user's feed—require extended permission from a user before Facebook allows your application to perform them. This is very similar to some features of the iPhone SDK. Even though your application has been approved by Apple to run on any iPhone device, your application must still request explicit permission from the end user to gain access to the device's location data. Even the App Store requires you to reenter your password after a short span of time.
Here's a test you might find interesting. Try clicking the Publish to Feed button without first clicking the Get Permission button. What do you expect will happen? Do you think Facebook will allow you to publish anything to a user's feed without that user's explicit permission? If you said Facebook would prevent this unauthorized access to the user's feed, then you are correct. Facebook Connect protects users from both intentional and accidental threats to their privacy.
Tip
Be sure to check out the video “How To: Implement Facebook Connect on the iPhone in 5 Minutes,” located at www.vimeo.com/3616452.
Creating a new Facebook Connect application
Now you will learn how to create a Facebook Connect iPhone application from scratch. Open Xcode and choose File⇒New Project. Be sure that Application is selected under iPhone OS in the left-hand template listing. Choose the Utility Application template and click the Choose button, as shown in Figure 6.19.
FIGURE 6.19
New Project template dialog box
Name the new project Facebook or another name of your own choosing, and then click the Save button. Facebook recommends reusing the FBConnect code they provide you in the fbconnect-iphone.zip file, versus trying to re-create this base code every time yourself. That is the approach we will follow here.
Go back to the files you extracted from the fbconnect-iphone.zip and click on the included src folder to open it. Double-click on FBConnect.xcodeproj to open the FBConnect project in Xcode. Find the FBConnect folder that is listed directly under the FBConnect project in the Groups & Files listing on the left-hand side of Xcode (Figure 6.20).
Drag the FBConnect folder from the FBConnect project into the other Facebook project. Be sure to drag it under the Facebook project, and not into another folder already in the Facebook project. After you finish copying the FBConnect folder, Xcode shows an options dialog box. Be sure to uncheck the Copy items into destination group's folder (if needed) check box. Also confirm that the Reference Type field is set to Default and that Text Encoding is set to Unicode (UTF-8). Once you have verified the settings, click the Add button.
FIGURE 6.20
FBConnect project open in Xcode
If you try to build the application now, Xcode will return with many errors and warnings. In order for Xcode to successfully compile this project, you will need to add a new framework to this project. Again in the Groups & Files listing, find the Frameworks folder under the FBConnect project. Right-click on the folder and choose Add⇒Existing Framework. You should see the screen shown in Figure 6.21.
Open the Frameworks folder and select the CoreGraphics.framework folder, then