使用WKWebView:
まず、あなたが必要import WebKit
。次に、このようにそれを初期化します。
let url = URL(string: "https://itunes.apple.com/us/album/burn-that-broken-bed/id1120162623?i=1120163074&uo=4")!
let wkWebView = WKWebView(frame: self.view.frame, configuration: WKWebViewConfiguration())
wkWebView.uiDelegate = self // Optional line - must conform to WKUIDelegate
// the line below specifies the custom agent, which allows you to request the desktop version of the website
wkWebView.customUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36"
wkWebView.load(URLRequest(url: url))
self.view.addSubview(wkWebView)
更新:あなたはそれを追加する必要がありますので、(WKWebViewの統合)
残念ながら、あなたは、XCodeの8のようIBでWKWebViewを追加することはできません。プログラム的に(未テストコード)
// for ease of use
extension WKWebView {
func setDesktopMode(on: Bool) {
if on {
customUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36"
return
}
customUserAgent = nil
}
}
そして、あなたの中に:ここで良いニュースは、あなたがこのうちのわずかWKWebViewオブジェクト
チェックのプログラムでインスタンス化を容易にするためにあなたはIBで作成したのUIWebViewのframe
を使用することができるということですカスタムセルファイル
class MyCustomCell: UICollectionViewCell {
var wkWebView: WKWebView! // add this line
@IBOutlet weak var webView: UIWebView! // the one you created in IB
}
あなたのUIViewControllerで次に func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CellIdentifier", for: indexPath) as! MyCustomCell
let url = URL(string: "url here")!
cell.wkWebView = WKWebView(frame: cell.webView.frame, configuration: WKWebViewConfiguration()) // using the webView's frame that was created in IB
cell.wkWebView.uiDelegate = self // Optional line - must conform to WKUIDelegate
cell.wkWebView.setDesktopMode(on: true) // true = loads desktop mode (for your iTunes URLs)
cell.wkWebView.load(URLRequest(url: url))
return cell
}
Webビューで表示する特別な理由はありますか?そうでない場合は、実際のアプリケーションページとそのボタンをインストールするSKStoreProductViewControllerポップアップを常に使用することができます。 –
私はウェブビューのコレクションビューを提示しています。iTunesリンクは、ユーザーに表示したいセルのタイプの1つです。つまり、SoundCloud YouTube Spotifyなどと一緒です。 – GarySabo