iOS9 中有没有一种方法可以隐藏状态栏中的“返回Safari”?

21

如何以编程方式隐藏状态栏中的“<回到Safari”?

enter image description here

当我从我的应用程序中退出时,如果用户想要使用其Facebook帐户登录,则在我的应用程序中收到此消息。

以下是我不喜欢(想要)在我的应用程序中出现“回到Safari”的情况:

  1. 首次启动应用程序(且用户未登录)。
  2. 用户选择使用Facebook选项登录。
  3. Facebook iOS SDK出现,将我带到Safari。
  4. 我登录并返回到应用程序
  5. 但是,“回到Safari”还在这里……它不应该再出现了。

1
最好不要在这里问关于beta操作系统的问题,而是在苹果的beta论坛中提问。在这里发布 - https://forums.developer.apple.com/community/pre-release/ios-9-beta - Tushar
这不是一个与 bug 相关的问题。我想知道是否可以通过编程方式来隐藏它?因为一旦关闭(移除)Safari 浏览器,该消息将被移除。但我不希望出现这种行为,因为我不希望我的用户回到 Safari。 - Hemang
1
找到解决方案了吗? - Easwaramoorthy K
@EaswaramoorthyK,不,还没有。 - Hemang
2个回答

4
不,目前没有提供相关API支持。

1
我们能至少覆盖这个动作吗? - Easwaramoorthy K
1
太好了,我已经编写了逻辑来打开其他应用程序并返回到我的应用程序,但这个按钮搞乱了我的整个逻辑 - 我不明白为什么它可以被禁用? - new2ios
我找不到任何关于这个的文档。我认为我们根本不能碰它。 - Zia

0

您可以通过转发到一个带有返回到您的应用程序的网站来实现此目的。以下步骤允许您隐藏状态栏中的“返回Safari”,MyApp是示例应用程序名称:

  1. 将您的应用程序URL Scheme添加到Info.plist中

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>myapp</string>
    </array>
    
  2. 在网站上设置自定义URL转发(例如http://example.com/myapp

    _redirect_rule_from /myapp
    _redirect_rule_to myapp://
    
  3. 在授权方法闭包中,访问您在步骤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];
        }
       };
    
     }];
    
    }
    

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接