swift,xcodeの超超初心者です。
前提・実現したいこと
iOSで位置情報を得るために、CLLocationManagerを使おうとしていますが
以下のビルドエラーが発生します。
発生している問題・エラーメッセージ
Instance member 'requestLocation' cannot be used on type 'CLLocationManager'; did you mean to use a value of this type instead?
該当のソースコード
swift
1import CoreLocation 2 3final class RentalViewController: BusinessViewController, UITableViewDataSource, UITableViewDelegate, ReceiptCompletedDelegate, CLLocationManagerDelegate { 4 5 var locMng: CLLocationManager! 6 7 init(titleName: String) { 8 self.locMng = CLLocationManager() 9 super.init(nibName: nil, bundle: nil) 10 self.locMng.delegate = self 11 } 12 13 private func save() -> Bool { 14 do { 15 if #available(iOS 9.0, *){ 16 self.locMng.requestLocation() ←ここでビルドエラー 17 } 18 } catch { 19 return false 20 } 21 return true 22 } 23 24 func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus){ 25 switch status { 26 case .notDetermined: 27 manager.requestWhenInUseAuthorization() 28 break; 29 case .authorizedWhenInUse: 30 NSLog("許可されました") 31 break; 32 case .denied: 33 NSLog("拒否されました") 34 break; 35 default: 36 break; 37 } 38 } 39 func locationManager(_ manager: CLLocationManager!,didUpdateLocations locations:[AnyObject]!){ 40 NSLog(String(format:"%.3f",manager.location?.coordinate.latitude.description ?? 0.0)+"/"+String(format:"%.3f",manager.location?.coordinate.longitude.description ?? 0.0)) 41 } 42 func locationManager(_ manager: CLLocationManager, didFailWithError error: Error){ 43 Logger.write(error) 44 } 45}
試したこと
特にはありません。
参考にしたサイトです。
https://qiita.com/shngt/items/258a71a6524941efd12d
https://dev.classmethod.jp/smartphone/ios-corelocation-swift3/
補足情報(FW/ツールのバージョンなど)
swift4.2,xcode10.1,macOS10.4.3(開発マシン)
参考にしているサイトが、どちらも2年以上前のものなので情報が古い可能性があります。また、macOSとiOSは別物です(iOSはmacOSをベースにしているが、iPhoneなどの携帯デバイス用になっている)。
質問のコードを少し修正して試してみましたがエラーを再現できません。
再現できる最小限のコードを用意して下さい。
ありがとうございます。
macOSは開発マシンのものです。iOSはxcodeのシミュレータを使っていますが、現在はiOS12.1で行っています。
参考サイトはたしかに古いですが、swift4に対応した情報が見つけられません。
恐れ入ります。
しばらく別なところを変更したり(他のコーダーのコードをマージしていたら)
エラーが出なくなってしまいました。
ひとまずなかったものとさせてください。
すみません。
回答1件
あなたの回答
tips
プレビュー