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.
- At first launch of the app (and user not logged in).
- User choose Login with Facebook option.
- Facebook iOS SDK comes into the picture, it takes me to the Safari.
- I logged in and back to the app
- But, there's "Back to Safari"... It shouldn't be here anymore.
No, there is no API that lets you do this.
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:
Add your application URL Scheme to the Info.plist
<key>LSApplicationQueriesSchemes</key> <array> <string>myapp</string> </array>
Setup a custom URL forward on a website (e.g. http://example.com/myapp)
_redirect_rule_from /myapp _redirect_rule_to myapp://
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