我正在開發一款iphone遊戲,我想讓用戶在Facebook上發佈他們的分數。我設法實現它,但每次我想要發佈Feed時,都會有一個Facebook窗口告訴我我已經登錄到了我的Facebook應用程序,並且用戶需要點擊接受才能顯示將feed發佈到的nex窗口輪廓的牆。iPhone - Facebook連接
我需要跳過Facebook登錄嗎?我的意思是Facebook授權方法,並直接跳入Facebook的飼料方法?
這是我的,但會話總是無效的! fbDidLogin不會被調用,並在調試它給MES這樣那樣的錯誤:
void SendDelegateMessage(NSInvocation*): delegate (webView:decidePolicyForNavigationAction:request:frame:decisionListener:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode
如果我註銷,然後嘗試喂,我必須先登錄2次,一個用於會話,一個用於飼料。
這是代碼:
#import "FacebookConnect.h"
static NSString* kAppId = @"414427041919461"; // Your Facebook app ID here
@implementation FacebookConnect
@synthesize facebook = _facebook;
#pragma mark -
#pragma mark Singleton Variables
static FacebookConnect *singletonDelegate = nil;
#pragma mark -
#pragma mark Singleton stuff
- (id)init {
if (!kAppId) {
NSLog(@"MISSING APP ID!!!");
exit(1);
return nil;
}
if ((self = [super init])) {
_facebook = [[Facebook alloc] initWithAppId:kAppId andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
_facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
_facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
}
return self;
}
+(FacebookConnect *) sharedFacebook
{
@synchronized([FacebookConnect class])
{
if(!singletonDelegate) [[self alloc] init];
return singletonDelegate;
}
return nil;
}
+(id)alloc
{
@synchronized ([FacebookConnect class])
{
NSAssert(singletonDelegate == nil, @"Attempted to allocate a second instance of the Game Manager singleton");
singletonDelegate = [super alloc];
return singletonDelegate;
}
return nil;
}
#pragma mark -
#pragma mark Singleton methods
-(void) logout
{
[_facebook logout];
}
-(void) feedWithScore:(int) _s andLevel:(int) _l
{
if (![_facebook isSessionValid]) {
NSLog(@"Session invalid - Authorize");
/*NSArray *permissions = [[NSArray alloc] initWithObjects:@"user_likes", @"read_stream",nil];
[_facebook authorize:permissions];
[permissions release];*/
[_facebook authorize:nil];
}
[_facebook dialog:@"feed" andDelegate:self];
}
#pragma mark -
#pragma mark Facebook implementations
// Pre iOS 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [_facebook handleOpenURL:url];
}
// For iOS 4.2+ support
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [_facebook handleOpenURL:url];
}
- (void)fbDidLogin {
NSLog(@"Login OK");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[_facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[_facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
- (void) fbDidLogout {
NSLog(@"Log out");
// Remove saved authorization information if it exists
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]) {
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
}
- (void)dialogDidComplete:(FBDialog *)dialog{ NSLog(@"Login OK"); }
- (void)dialogDidNotComplete:(FBDialog *)dialog{}
- (void)dialogCompleteWithUrl:(NSURL *)url{}
- (void)dialog:(FBDialog*)dialog didFailWithError:(NSError *)error{}
- (BOOL)dialog:(FBDialog*)dialog shouldOpenURLInExternalBrowser:(NSURL *)url{return NO;}
- (void)fbDidNotLogin:(BOOL)cancelled{}
- (void)fbDidExtendToken:(NSString*)accessToken
expiresAt:(NSDate*)expiresAt{}
- (void)fbSessionInvalidated{}
#pragma mark -
#pragma mark Dealloc
-(void) dealloc{
[super dealloc];
[_facebook release];
}
@end
好它並不是每次facebook都需要permis錫永。這是有一個窗口,它只是說用戶已登錄wth我的Facebook應用程序 – marcg11 2012-04-16 09:33:06
我不確定你的意思。如果您要求提供所需的所有權限,則只需授權一次。每次您的應用加載時,您只需檢查一下該密鑰。查看我的編輯。 – 2012-06-19 16:02:04