LoginSignup
21
20

More than 5 years have passed since last update.

ATS対策 外部ページの表示にはSFSafariViewController

Posted at

iOS9でそんなに大きく取り上げられなかったのに開発者には頭のいたいATS, App Transfer Security
APIをいくつかしか使ってないってなら「対応待ち」「例外設定」などで対応できますが、
沢山の外部サイトにリンクするアプリの場合はどうするの?ってことで。
結論「SFSafariViewControllerを使おうよ(見た目気にしなければ)」ってことです。

SFSafariViewControllerは「SafariのVC実装」なので、HTTPのサイトも表示できます。
で、こんな感じで実装してあげます。

ViewController
    Class safari = NSClassFromString(@"SFSafariViewController");
    if (safari != nil) {
        SFSafariViewController *safariViewController =
        [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:@"http://example.com/"]];

        [self presentViewController:safariViewController
                           animated:YES
                         completion:nil];
    } else {
        //iOS8以下の場合の処理。独自またはサードパーティのWebViewController呼び出しなど。
    }

他にもやり方はそれぞれだろうとは思いますが、手っ取り早く外部リンク解決できます。
もちろん 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://example.com/"]];

ってSafari呼び出しもていいんですけどね。

21
20
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
20