前提・実現したいこと
Swift初心者です。
raywenderrich.comの記事を参考にさせて頂きながらカスタムキーボードを開発中です。
発生している問題・エラーメッセージ
参考にさせて頂いているraywenderlich.comの記事のStarterファイルをビルドしてみたのですが、下図のように何も表示されず、エラーが出てしまいました。新たに作成したカスタムキーボード拡張機能のSwiftファイル(keyboardviewcontroller.swift)と連携ができていないのかもしれないです。どなたかご回答して頂きたいです。下にファイル構成のスクショも貼っておきます。
MorseKeyboard[59137:6509431] [External] -[UIInputViewController needsInputModeSwitchKey] was called before a connection was established to the host application. This will produce an inaccurate result. Please make sure to call this after your primary view controller has been initialized.
keyboardviewcontroller.swift
swift
1/// Copyright (c) 2021 Razeware LLC 2/// 3/// Permission is hereby granted, free of charge, to any person obtaining a copy 4/// of this software and associated documentation files (the "Software"), to deal 5/// in the Software without restriction, including without limitation the rights 6/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7/// copies of the Software, and to permit persons to whom the Software is 8/// furnished to do so, subject to the following conditions: 9/// 10/// The above copyright notice and this permission notice shall be included in 11/// all copies or substantial portions of the Software. 12/// 13/// Notwithstanding the foregoing, you may not use, copy, modify, merge, publish, 14/// distribute, sublicense, create a derivative work, and/or sell copies of the 15/// Software in any work that is designed, intended, or marketed for pedagogical or 16/// instructional purposes related to programming, coding, application development, 17/// or information technology. Permission for such use, copying, modification, 18/// merger, publication, distribution, sublicensing, creation of derivative works, 19/// or sale is expressly withheld. 20/// 21/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27/// THE SOFTWARE. 28 29import UIKit 30 31class KeyboardViewController: UIInputViewController { 32 33 @IBOutlet var nextKeyboardButton: UIButton! 34 35 override func updateViewConstraints() { 36 super.updateViewConstraints() 37 38 // Add custom view sizing constraints here 39 } 40 41 override func viewDidLoad() { 42 super.viewDidLoad() 43 44 // Perform custom UI setup here 45 self.nextKeyboardButton = UIButton(type: .system) 46 47 self.nextKeyboardButton.setTitle(NSLocalizedString("Next Keyboard", comment: "Title for 'Next Keyboard' button"), for: []) 48 self.nextKeyboardButton.sizeToFit() 49 self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = false 50 51 self.nextKeyboardButton.addTarget(self, action: #selector(handleInputModeList(from:with:)), for: .allTouchEvents) 52 53 self.view.addSubview(self.nextKeyboardButton) 54 55 self.nextKeyboardButton.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true 56 self.nextKeyboardButton.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true 57 } 58 59 override func viewWillLayoutSubviews() { 60 self.nextKeyboardButton.isHidden = !self.needsInputModeSwitchKey 61 super.viewWillLayoutSubviews() 62 } 63 64 override func textWillChange(_ textInput: UITextInput?) { 65 // The app is about to change the document's contents. Perform any preparation here. 66 } 67 68 override func textDidChange(_ textInput: UITextInput?) { 69 // The app has just changed the document's contents, the document context has been updated. 70 71 var textColor: UIColor 72 let proxy = self.textDocumentProxy 73 if proxy.keyboardAppearance == UIKeyboardAppearance.dark { 74 textColor = UIColor.white 75 } else { 76 textColor = UIColor.black 77 } 78 self.nextKeyboardButton.setTitleColor(textColor, for: []) 79 } 80 81} 82
試したこと
上図のファイル構成の画像にもある通り、Target Membershipのところが原因かもしれないと思い、切り替えて見ましたが解決できませんでした。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。