In my app the user can post a link to his facebook wall. However, I cannot use the "authorize" method from the SDK to login the user because it's a no go for my client that the facebook app explicitly asks for all the (basic) permissions. Therefo开发者_StackOverflowre I immediately use a facebook dialog.
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: @"http://www.google.at", @"link", nil];
[self.facebook dialog:@"feed" andParams:params andDelegate:self];
This works fine but after the login when the user can post to his wall, the publish & cancel button always moves off screen (see screenshot). When I scroll down, the button immediately moves off screen again. This does not happen after a successful login. Does anybody know how I can keep the buttons on screen? Otherwise the user is not able to post the link.
I found this solution but at least for me it does not work: https://github.com/facebook/facebook-ios-sdk/issues/329
screenshot http://dl.dropbox.com/u/12018803/facebookPosting.png
I had the same problem and have a lot of time lost and find no solution but a workaround.
I have three methods
- (void) openMyFacebook
- (void) fbDidLogin
- (void) dialogFacebook
I call openMyFacebook
in - (void) openMyFacebook,
I alloc Facebook and look if there
are already stored keys in NSUserDefaults
if not I call [facebook authorize:nil delegate:self];
in the delegate - (void) fbDidLogin
I Store the Keys (same in the facbook example).
Then comes the trick.
Release facebook
[facebook release];
facebook = nil;
and start the - (void) openMyFacebook
again with the stored keys.
Works perfect.
- (void) openMyFacebook {
if (facebook == nil) {
facebook = [[Facebook alloc] initWithAppId:@"xxxxxxxxxx"];
}
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
[facebook authorize:nil delegate:self];
}
else {
[self dialogFacebook];
}
}
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
//release!!!!
[facebook release];
facebook = nil;
//and start again
[self openMyFacebook];
}
- (void) dialogFacebook {
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, @"app_id",
linkextern, @"link",
facebookImageUrlString, @"picture",
name, @"name",
@" ", @"message",
nil];
[facebook dialog:@"feed" andParams:params andDelegate:self];
}
精彩评论