Example: Integrating OFUnity for iOS With Your Application

It is assumed that you have the following installed:

OSX 10.6 or later Unity 3.3 or later Either:

XCode 4.0.2 and iOS SDK 4.3 from iOS Dev Center or XCode 3.2.5 and iOS SDK 4.2 from iOS Dev Center

OFUnity-iOS (Beta) SDK (which includes OFSDK 2.10.1i) A provisioned, physical iOS device connected to your computer; you will not be able to successfully build unless your device is connected

Try building and running the project before integrating OpenFeint:

Create a new empty project in Unity (File->New Project). Once created you should see an empty Project window. Select File->Build Settings If iOS is not the currently selected Platform, then select it and then click Switch Platform. Click the Player Settings button. Change the Bundle Identifier to match the bundle identifier that is compatible with your provisioning profile. (something like com.SomeCompany.OFTest).

Change SDK Version to iOS latest. Switch back to the Build Settings window. Make sure you still have iOS selected. Click Build (not Build and Run). In the Build iOS modal dialog box that appears:

Type UnityGenerated in the box labeled Save As:. Make sure your project folder name appears in the box label Where:. Click Save.

Open UnityGenerated/Unity-iPhone.xcodeproj in XCode. Make sure both the Unity and the iOS build targets are NOT simulators. Build/run. If the project builds and successfully runs, then you should see a blue screen from the default camera. If for any reason it doesnt work, then you either:

Do not have the proper versions of software installed. Missed a step above. Have not configured Unity iPhone properly

Integrating OpenFeint:

Unpack the OFUnity-iOS zip file into its own new folder (we’ll call this OFUnity). Copy OFUnity/OpenFeint.framework into the root directory of your new project (UnityGenerated). This folder should sit next to your Assets/ and Library/ folder. Copy OFUnity/OFResources_Universal.bundle into the root directory of your new project. This folder should sit next to your Assets/ and Library/ folder.

Open your empty project in Unity if it isnt already open. In Finder, double-click on OFUnity/OpenFeint-UnityiPhone.unitypackage. Make sure all items in the resulting dialog box are checked and then click the Import button. This step will add OpenFeint to the Unity menu. If it does not appear now, switch to another application and come back.

Select OpenFeint -> Set Application Initialization Settings…. When a dialog box appears, add a product key and secret obtained from your developer dashboard account. This step only needs to be done once for each application. It is recommended that you turn Allow Notifications on. Open the scene OpenFeint Test/OFUnityTest. Continue with either the XCode3 or XCode4 instructions below.

Building with XCode3:

XCode3 includes an AppleScript that automates steps that youd otherwise have to do in XCode. Make sure to close any existing projects you have open in XCode first. With the OFUnityTest scene open, select File->Build Settings Make sure you still have iOS selected. Click Build (_not _Build and Run). In the Build iOS modal dialog box that appears:

Type UnityGenerated in the box labeled Save As:. Make sure your project folder name appears in the box label Where:. Click Save. Select Replace to replace the existing project. In the future, you will select Append.

If the AppleScript completes successfully, you should be in XCode3 with your project open. Build and run to see if the application runs successfully. You should see menu buttons for Dashboard, Leaderboards, Achievements, etc. If for any reason it doesnt work, then you either:

Do not have the proper versions of software installed. Did not copy the OpenFeint framework and resource bundle correctly into the root of your project folder. Did not open the OFUnityTest scene before building Missed a step above.

Building with XCode4:

Unfortunately, AppleScript is broken with the current release of XCode4, which prevents the following steps from being automated. Make sure to close any existing projects you have open in XCode first. With the OFUnityTest scene open, select File->Build Settings Make sure you still have iOS selected. Make sure you are building for the physical device, both in Unity and in iOS. Click Build (_not _Build and Run). In the Build iOS modal dialog box that appears:

Type UnityGenerated in the box labeled Save As:. Make sure your project folder name appears in the box label Where:. Click Save. Select Replace to replace the existing project. In the future, you will select Append.

You should get an error dialog after your build notifying you that XCode4 AppleScript support is broken. The instructions referenced in that dialog are the ones you are following here. Open UnityGenerated/Unity-iPhone.xcodeproj in XCode. Select the Unity-iPhone project in Project navigator window. Select the Unity-iPhone Target in the editor window. Select the Build Settings tab. Switch the toggle from Basic to All. Switch the toggle from Combined to Levels. Under the Unity-iPhone project column find Other Linker Flags.

Add an -ObjC flag to both the Debug and Release configurations. Select the Build Phases tab at the top. Expand Copy Bundle Resources. Click the Add (+) button and then the Add Other button. If you are in your Unity-iPhone.xcodeproj folder, then two directories up to your root project folder. From your root project folder, select OFResources_Universal.bundle and click Open. Then, click Finish. Expand Link Binary With Libraries.

Click the Add (+) button and then the Add Other button. From your root project folder, select OpenFeint.framework and click Open. Click the Add (+) button and then the Add Other button. Add the following, additional frameworks:

AddressBook.framework AddressBookUI.framework CoreGraphics.framework GameKit.framework MapKit.framework MobileCoreServices.framework Security.framework libsqlite3.0.dylib libz.1.2.3.dylib

Build and run to see if the application runs successfully. You should see menu buttons for Dashboard, Leaderboards, Achievements, etc. If for any reason it doesnt work, then you either:

Do not have a device attached, or you are building for a Unity or iOS simulator. Do not have the proper versions of software installed. Did not copy the OpenFeint framework and resource bundle correct into the root of your project folder. Did not open the OFUnityTest scene before building Missed a step above.