Facebook iOS SDK 3.8 was used in my project, and now I upgrade it to 3.22.
A weird thing occurred during requesting "publish_actions" permission, which is the user need to input her account&password again. While in the previous version the part "login again" will just be skipped. I want to know if the logic in Facebook SDK changes, or I have to change the session handling process. Any ideas on this problem?
The way I used to request the "publish_actions" permission is:
[activeSession openWithBehavior: FBSessionLoginBehaviorForcingWebView
completionHandler:^(FBSession *session,
FBSessionState state, NSError *error) {
[session reauthorizeWithPermissions:@[@"publish_actions"]
isRead:NO
behavior:FBSessionLoginBehaviorForcingWebView
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
}
And I also tried
[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
__block NSString *alertText;
__block NSString *alertTitle;
_reauthorizeInProgress = YES;
if (!error) {
if ([FBSession.activeSession.permissions
indexOfObject:@"publish_actions"] == NSNotFound){
// Permission not granted, tell the user we will not publish
alertTitle = @"Permission not granted";
alertText = @"Your action will not be published to Facebook.";
[[[UIAlertView alloc] initWithTitle:alertTitle
message:alertText
delegate:self
cancelButtonTitle:@"OK!"
otherButtonTitles:nil] show];
} else {
// Permission granted, publish the OG story
}
} else {
// There was an error, handle it
// See https://developers.facebook.com/docs/ios/errors/
}
}];
This behavior is the default set by Facebook. The document https://developers.facebook.com/docs/facebook-login/ios/v2.2 says that:
The Disadvantage of WebView is:
People have to fill in their login credentials every time they go through the login flow.
In the FBSession.m file, I change the code in method
- (void)retryableAuthorizeWithPermissions:(NSArray *)permissions
defaultAudience:(FBSessionDefaultAudience)defaultAudience
integratedAuth:(BOOL)tryIntegratedAuth
FBAppAuth:(BOOL)tryFBAppAuth
safariAuth:(BOOL)trySafariAuth
fallback:(BOOL)tryFallback
isReauthorize:(BOOL)isReauthorize
canFetchAppSettings:(BOOL)canFetchAppSettings
And do not delete cookie when asking for another permission, replace
// To avoid surprises, delete any cookies we currently have.
[FBUtility deleteFacebookCookies];
with
// To avoid surprises, delete any cookies we currently have.
if(!isReauthorize){
[FBUtility deleteFacebookCookies];
}
I agree that it is not a good idea to modify the SDK source, while I should make some balance between the consistence of user experience and the code style. ;(