前提・実現したいこと
swift超初心者です。勉強しながら
XCODE10.1を使用して任意のWeb画面を表示させるシンプルなアプリを作りました。
最終的にCarplay対応にしたいと考えています。
色々Webで参考になりそうな記事を探しましたが、
私の知識が足りないが故に、なかなか実現できずにいます。
1)webView.entitlementsを作成し、「com.apple.developer.playable-content」の設定は済んでいます。
2)下記のソースでCarplay表示を実現しようとしていますが、シュミレーターにアイコンも出てきません。。
通常のiPhone側シュミレーターでは正常に表示されています。
該当のソースコード ###
<AppDelegate.swiftのソース編集>
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow? var carWindow: UIWindow? func updateCarWindow() { guard let screen = UIScreen.screens.first(where: {$0.traitCollection.userInterfaceIdiom == .carPlay}) else { self.carWindow = nil return } // CarPlay is connected let carWindow = UIWindow(frame: screen.bounds) carWindow.screen = screen carWindow.makeKeyAndVisible() carWindow.rootViewController = ViewController() self.carWindow = carWindow } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true }
<Web表示部分>
import UIKit
class ViewController: UIViewController,UIWebViewDelegate {
override func viewDidLoad() { super.viewDidLoad() //画面一杯にWebを表示 let myWebView : UIWebView = UIWebView() myWebView.delegate = self myWebView.frame = self.view.bounds self.view.addSubview(myWebView) let url: NSURL = NSURL(string: "https://youtube.com")! let request: NSURLRequest = NSURLRequest(url: url as URL) myWebView.loadRequest(request as URLRequest) } //ページが読み終わったときに呼ばれる関数 func webViewDidFinishLoad(_ webView: UIWebView) { } //ページを読み始めた時に呼ばれる関数 func webViewDidStartLoad(_ webView: UIWebView) { } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() }
}
ここにより詳細な情報を記載してください。
Carplayに表示できる方法をなんとか知りたいです。。
とにかく情報が少なく困っています。
あなたの回答
tips
プレビュー