gpt4 book ai didi

ios - XCode 7 - Swift - 通过 SFSafariViewController 自动加载站点

转载 作者:行者123 更新时间:2023-11-28 21:36:18 25 4
gpt4 key购买 nike

我正在更新我们的 iTunes 应用程序,并且想利用新的 SFSafariViewController api。用例非常简单,当用户打开应用程序时,应用程序会自动加载 SFSafariViewController 中设置的 url。

关于这方面的教程似乎有限,并且确实存在的教程在应用程序打开后通过链接涉及 IBActions。

当用户点击其设备上的应用程序时,如何在 SFSafariViewController 中自动打开链接?

以下代码只是白页:

import UIKit
import SafariServices

class ViewController: UIViewController
{
private var urlString:String = "https://example.com"

override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

let svc = SFSafariViewController(URL: NSURL(string: self.urlString)!)

svc.presentViewController(self, animated: true, completion: nil)
}

override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

----工作代码----

import UIKit
import SafariServices

class ViewController: UIViewController
{
private var urlString:String = "https://example.com"

override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

override func viewDidAppear(animated: Bool) {

super.viewDidAppear(animated)

let svc = SFSafariViewController(URL: NSURL(string: self.urlString)!)

self.presentViewController(svc, animated: true, completion: nil)
}
}

最佳答案

您当前的代码正在尝试显示 SFSafariViewController 中的当前 View Controller (ViewController),它甚至还没有被显示.

尝试交换这个:

svc.presentViewController(self, animated: true, completion: nil)

为此:

self.presentViewController(svc, animated: true, completion: nil)

关于ios - XCode 7 - Swift - 通过 SFSafariViewController 自动加载站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33809985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com