如何以编程方式从状态栏中隐藏此 < Back to Safari?
我在我的应用程序中获取它——如果用户想使用他们的 Facebook 帐户登录,我将从我的应用程序中退出。
这是我不喜欢(想要)在我的应用程序中“返回 Safari”的场景。
- 首次启动应用程序时(用户未登录)。
- 用户选择使用 Facebook 登录选项。
- Facebook iOS SDK 出现了,它把我带到了 Safari。
- 我登录并返回应用程序
- 但是,有“回到 Safari”……它不应该再出现了。
如何以编程方式从状态栏中隐藏此 < Back to Safari?
我在我的应用程序中获取它——如果用户想使用他们的 Facebook 帐户登录,我将从我的应用程序中退出。
这是我不喜欢(想要)在我的应用程序中“返回 Safari”的场景。
不,没有 API 可以让您执行此操作。
您可以通过转发到带有转发回您的应用程序的网站来实现此目的。以下步骤允许您在状态栏中隐藏“返回 Safari”,MyApp 是示例应用程序名称:
将您的应用程序 URL 方案添加到 Info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>myapp</string>
</array>
在网站上设置自定义 URL 转发(例如http://example.com/myapp)
_redirect_rule_from /myapp
_redirect_rule_to myapp://
在您的授权方法关闭中点击您在步骤 2 中创建的转发
- (void)willLoginWithFacebook
{
__weak __typeof(self) weakSelf = self;
[self.view setUserInteractionEnabled:NO];
[self.sessionManager authenticateViaFacebookWithCompletion:^(NSString *token, NSSet *grantedPermissions,
NSError *error) {
if (error) {
if (error.code != myappErrorCodeCancelled) {
[weakSelf.rootViewController presentError:error];
}
}
else {
[weakSelf authorizeWithFacebookToken:token];
NSString *customURL = @"myapp://";
if ([[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:customURL]])
{
NSString *stringURL = @"http://example.com/myapp";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"URL error"
message:[NSString stringWithFormat:
@"No custom URL defined for %@", customURL]
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
}
};
}];
}