Having trouble integrating Facebook into my app with the iOS Facebook SDK. Anyone have any success? Im not getting a callback to fbDidLogin or handleOpenURL. It does however go to my app in Facebook. Here is my code in my delegate: Another scene calls the login function to start it.
#import "cocos2d.h"
#import "AppDelegate.h"
#import "GameConfig.h"
#import "SongSelectScene.h"
#import "RootViewController.h"
@implementation AppDelegate
@synthesize window;
@synthesize facebook;
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
[UIApplication sharedApplication].idleTimerDisabled = YES;
facebook = [[Facebook alloc] initWithAppId:@"208716155855212" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"])
{
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
[CCDirector setDirectorType:kCCDirectorTypeDefault];
CCDirector *director = [CCDirector sharedDirector];
// Init the View Controller
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];
[director setOpenGLView:glView];
[[director openGLView] setMultipleTouchEnabled:YES];
if(![director enableRetinaDisplay:YES])
CCLOG(@"Retina Display Not supported");
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif
[director setAnimationInterval:1.0/60];
[director setDisplayFPS:YES];
// make the OpenGLView a child of the view controller
[viewController setView:glView];
// make the View Controller a child of the main window
[window addSubview: viewController.view];
[window makeKeyAndVisible];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
// Run the intro Scene
[[CCDirector sharedDirector] runWithScene: [SongSelectScene scene]];
}
- (void)login
{
NSArray* permissions = [[NSArray arrayWithObjects:
@"publish_stream", @"read_stream", nil] retain];
if (![facebook isSessionValid])
[facebook authorize:permissions];
}
- (void)fbDidLogin
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
[[CCDirector sharedDirector] pause];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[CCDirector sharedDirector] resume];
}
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
[[CCDirector sharedDirector] purgeCachedData];
}
-(void) applicationDidEnterBackground:(UIApplication*)application
{
[[CCDirector sharedDirector] stopAnimation];
}
-(void) applicationWillEnterForeground:(UIApplication*)application
{
[[CCDirector sharedDirector] startAnimation];
}
- (void)applicationWillTerminate:(UIApplication *)application
{
CCDirector *director = [CCDirector sharedDirector];
[[director openGLView] removeFromSuperview];
[viewController release];
[window release];
[director end];
}
- (void)applicationSignificantTimeChange:(UIApplication *)application
{
[[CCDirector sharedDirector] setNextDeltaTimeZero:YES];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [facebook handleOpenURL:url];
}
- (void)dealloc
{
[[CCDirector sharedDirector] end];
[window release];
[facebook release];
[super dealloc];
}
@end
Does anyone have some sample code or can help me get on track? Just looking to do a basic wall post with a high score. Nothing fancy. Thanks!