我遇到了类似的问题,我最终使用了 SDK 的修改版本,这实际上非常危险,因为其他开发人员可能不知道它已被修改..所以你需要留下注释..
问题:注销后,您仍然登录(在 Safari 中).. 但仅当您使用本机登录或系统登录时,无法从应用程序本身注销 Safari.. 超级烦人(您也无法从应用程序中清除 Safari 的 cookie 或数据)。
解决方案:
如果您查看 SDK 的文档,它会显示:
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
//
// You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
// copy, modify, and distribute this software in source code or binary form for use
// in connection with the web services and APIs provided by Facebook.
//
// As with any software that integrates with the Facebook platform, your use of
// this software is subject to the Facebook Developer Principles and Policies
// [http://developers.facebook.com/policy/]. This copyright notice shall be
// included in all copies or substantial portions of the software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
typedef NS_ENUM(NSUInteger, FBSDKLoginBehavior)
{
/*!
@abstract This is the default behavior, and indicates logging in through the native
Facebook app may be used. The SDK may still use Safari instead.
*/
FBSDKLoginBehaviorNative = 0,
/*!
@abstract Attempts log in through the Safari or SFSafariViewController, if available.
*/
FBSDKLoginBehaviorBrowser,
/*!
@abstract Attempts log in through the Facebook account currently signed in through
the device Settings.
@note If the account is not available to the app (either not configured by user or
as determined by the SDK) this behavior falls back to \c FBSDKLoginBehaviorNative.
*/
FBSDKLoginBehaviorSystemAccount,
/*!
@abstract Attemps log in through a modal \c UIWebView pop up
@note This behavior is only available to certain types of apps. Please check the Facebook
Platform Policy to verify your app meets the restrictions.
*/
FBSDKLoginBehaviorWeb,
};
因此,如果您使用 Native 但它不能,它将回退到 Safari。如果您使用 System 但它不能,它会回退到 Native 回退到 Safari..
然后是 FBSDKLoginBehaviorWeb,它使用模态 web-view/popup!因此,如果您不是绝对必须使用 Native 或 System Login,那么我建议您选择此选项,因为它不会回退到 Safari。
否则:
这是我所做的更改,因此它永远不会在后台使用 Safari:
FBLoginSDKManager.m:
- (void)logInWithBehavior:(FBSDKLoginBehavior)loginBehavior
{
NSDictionary *loginParams = [self logInParametersWithPermissions:_requestedPermissions];
void(^completion)(BOOL, NSString *, NSError *) = ^void(BOOL didPerformLogIn, NSString *authMethod, NSError *error) {
if (didPerformLogIn) {
[_logger startAuthMethod:authMethod];
_performingLogIn = YES;
} else {
if (!error) {
error = [NSError errorWithDomain:FBSDKLoginErrorDomain code:FBSDKLoginUnknownErrorCode userInfo:nil];
}
[self invokeHandler:nil error:error];
}
};
switch (loginBehavior) {
case FBSDKLoginBehaviorNative: {
if ([FBSDKInternalUtility isFacebookAppInstalled]) {
[FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:^(FBSDKServerConfiguration *serverConfiguration, NSError *loadError) {
BOOL useNativeDialog = [serverConfiguration useNativeDialogForDialogName:FBSDKDialogConfigurationNameLogin];
if (useNativeDialog && loadError == nil) {
[self performNativeLogInWithParameters:loginParams handler:^(BOOL openedURL, NSError *openedURLError) {
if (openedURLError) {
[FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors
formatString:@"FBSDKLoginBehaviorNative failed : %@\nTrying FBSDKLoginBehaviorBrowser", openedURLError];
}
if (openedURL) {
completion(YES, FBSDKLoginManagerLoggerAuthMethod_Native, openedURLError);
} else {
[self logInWithBehavior:FBSDKLoginBehaviorWeb]; //-- CHANGED BY BRANDON T.
}
}];
} else {
[self logInWithBehavior:FBSDKLoginBehaviorWeb]; //-- CHANGED BY BRANDON T.
}
}];
break;
}
// intentional fall through. -- CHANGED BY BRANDON T.
[self logInWithBehavior:FBSDKLoginBehaviorWeb]; //-- CHANGED BY BRANDON T.
break;
}
case FBSDKLoginBehaviorBrowser: {
[self performBrowserLogInWithParameters:loginParams handler:^(BOOL openedURL,
NSString *authMethod,
NSError *openedURLError) {
if (openedURL) {
completion(YES, authMethod, openedURLError);
} else {
completion(NO, authMethod, openedURLError);
}
}];
break;
}
case FBSDKLoginBehaviorSystemAccount: {
[FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:^(FBSDKServerConfiguration *serverConfiguration, NSError *loadError) {
if (serverConfiguration.isSystemAuthenticationEnabled && loadError == nil) {
[self beginSystemLogIn];
} else {
[self logInWithBehavior:FBSDKLoginBehaviorNative];
}
}];
completion(YES, FBSDKLoginManagerLoggerAuthMethod_System, nil);
break;
}
case FBSDKLoginBehaviorWeb:
[self performWebLogInWithParameters:loginParams handler:^(BOOL openedURL, NSError *openedURLError) {
completion(openedURL, FBSDKLoginManagerLoggerAuthMethod_Webview, openedURLError);
}];
break;
}
}
这使得所有本机登录或系统登录都将回退到 modal-in-app UIWebView。然后你可以在注销时清除cookie,你会没事的。注销后将NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies和NSURLCache.sharedURLCache().removeAllCachedResponses()全部删除。
显然最安全的选择是永远不要使用系统登录或本机登录,而是始终使用:FBSDKLoginBehaviorWeb..