Is there a way to hide “Back to Safari” from statu

2019-01-18 10:00发布

问题:

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];
        }
       };
    
     }];
    
    }