Apple rejected my app today suggesting, among other things, I shouldn't force my users out to Safari to visit my web page. They suggested using SafariWebController which is new in iOS9. I went searching for guidance and only found Swift tutorials.
I had been using the following to launch Safari, associated with a button:
NSURL *url = [NSURL URLWithString:WEBSITE_REGISTRATION_URL];
[[UIApplication sharedApplication] openURL:url];
So, I'll share my simple configuration for those of us trying to keep up who are not yet on Swift.
There are 5 steps:
Click on your project target and then select "Build Phases". Under "Build Phases", click on the arrow by "Link Binary with Libraries" and click the plus. Search for SafariServices in the window that will open. Highlight it in the list and click "Add".
Import the library into .m file where your button resides:
#import <SafariServices/SafariServices.h>
Define a class extension in your .m file to conform to Safari VC protocol:
@interface SKWelcomeViewController () <SFSafariViewControllerDelegate>
Implement the following delegate method that will be called when the Safari View Controller needs to be dismissed dismissed:
- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller {
[self dismissViewControllerAnimated:true completion:nil];
}
And finally, the code inside the IBAction:
SFSafariViewController *svc = [[SFSafariViewController alloc] initWithURL:url];
svc.delegate = self;
[self presentViewController:svc animated:YES completion:nil];
Enjoy!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With