How to use SafariViewController in Objective-c?

Apple rejected my application today, proposing, among other things, not to force my users to Safari to visit my web page. They suggested using SafariWebController, which is new in iOS9. I went looking for guidance and found only Swift tutorials.

I used the following to launch the Safari associated with the button:

NSURL *url = [NSURL URLWithString:WEBSITE_REGISTRATION_URL]; [[UIApplication sharedApplication] openURL:url]; 

So, I will share my simple configuration for those of us who are trying to save those who are not already in Swift.

+5
source share
1 answer

There are 5 steps:

  • Click on the goal of your project, and then select "Form Phases." In the "Phase Build" section, click on the "Link Binary Files to Libraries" arrow and click "Plus." Locate SafariServices in the window that opens. Highlight it in the list and click "Add." enter image description here

  • Import the library into the .m file where your button is located:

     #import <SafariServices/SafariServices.h> 
  • Define the class extension in your .m file to comply with the VC Safari protocol:

     @interface SKWelcomeViewController () <SFSafariViewControllerDelegate> 
  • Implement the following delegate method, which will be called if the Safari View Controller rejection is rejected:

     - (void)safariViewControllerDidFinish:(SFSafariViewController *)controller { [self dismissViewControllerAnimated:true completion:nil]; } 
  • And finally, the code inside IBAction:

     SFSafariViewController *svc = [[SFSafariViewController alloc] initWithURL:url]; svc.delegate = self; [self presentViewController:svc animated:YES completion:nil]; 

Enjoy it!

+21
source

Source: https://habr.com/ru/post/1237953/


All Articles