olası iş çevresinde yönlendiriyor yerine amaçlanan içeriği görüntüler web sitesinin masaüstü modu talep etmektir.
kullanma WKWebView:
Öncelikle yapmanız gerekir 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)
Güncelleme:
Maalesef (WKWebView entegre) kullanarak, XCode 8 gibi IB bir WKWebView ekleyemezsiniz, bu yüzden eklemek gerekecek Sonra bunu böyle başlatmak programlı. Burada iyi haber size biraz WKWebView nesne
Kontrol şuna programatik örnekleme kolaylaştırmak için IB oluşturulan UIWebView arasında frame
kullanabilirsiniz olmasıdır: (denenmemiş kodu)
// 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
}
}
Ve de senin özel hücre dosyası UIViewController Sonra
class MyCustomCell: UICollectionViewCell {
var wkWebView: WKWebView! // add this line
@IBOutlet weak var webView: UIWebView! // the one you created in IB
}
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 görünümde göstermek istediğiniz belirli bir sebep var mı? Değilse, her zaman gerçek uygulama sayfasını görüntüleyecek olan bir SKStoreProductViewController açılır ve bunu yüklemek için bir düğme kullanabilirsiniz. –
Web görünümlerinden oluşan bir koleksiyon görünümü sunarım ve iTunes bağlantıları, kullanıcıya göstermek istediğim hücre türlerinden biri. Örneğin SoundCloud YouTube Spotify ile birlikte – GarySabo