Is there a way to hide “Back to Safari” from status bar in iOS9?

梦想的初衷 提交于 2019-12-28 14:09:09

问题


How to hide this < Back to Safari from status bar programmatically?

I'm getting it in my app – as I'm going out from my app if a user wants to login with their Facebook account.

Here's the scenario for which I don't like (want) "Back to Safari" in my app.

  1. At first launch of the app (and user not logged in).
  2. User choose Login with Facebook option.
  3. Facebook iOS SDK comes into the picture, it takes me to the Safari.
  4. I logged in and back to the app
  5. But, there's "Back to Safari"... It shouldn't be here anymore.

回答1:


No, there is no API that lets you do this.




回答2:


You can achieve this by forwarding to a website with a forward back to your app. The following steps allows you to hide the 'Back to Safari' in the status bar, MyApp is the example app name:

  1. Add your application URL Scheme to the Info.plist

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>myapp</string>
    </array>
    
  2. Setup a custom URL forward on a website (e.g. http://example.com/myapp)

    _redirect_rule_from /myapp
    _redirect_rule_to myapp://
    
  3. In your authorization method closure hit the forward you created in step 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];
        }
       };
    
     }];
    
    }
    


来源:https://stackoverflow.com/questions/31247787/is-there-a-way-to-hide-back-to-safari-from-status-bar-in-ios9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!