Ios 使用CL位置的基于位置的应用程序。我的代码中有一行出现问题

Ios 使用CL位置的基于位置的应用程序。我的代码中有一行出现问题,ios,swift,xcode,core-location,cllocation,Ios,Swift,Xcode,Core Location,Cllocation,我正在制作此应用程序,并不断获取此类型为“LocationsStorage”的错误值,该值没有成员“saveCLLocationToDisk” 我不明白为什么会有这样的问题,我甚至试着查看苹果网站上的文档,但我仍然不知道问题出在哪里。该行在第4节之后 import UIKit import CoreLocation import UserNotifications @UIApplicationMain class AppDelegate: UIResponder, UIApplication

我正在制作此应用程序,并不断获取此类型为“LocationsStorage”的错误值,该值没有成员“saveCLLocationToDisk”

我不明白为什么会有这样的问题,我甚至试着查看苹果网站上的文档,但我仍然不知道问题出在哪里。该行在第4节之后

import UIKit
import CoreLocation
import UserNotifications

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate {
  var window: UIWindow?
  static let geoCoder = CLGeocoder()

  let center = UNUserNotificationCenter.current()
  let locationManager = CLLocationManager()

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    let rayWenderlichColor = UIColor(red: 0/255, green: 104/255, blue: 55/255, alpha: 1)
    UITabBar.appearance().tintColor = rayWenderlichColor
    center.requestAuthorization(options: [.alert, .sound]) { granted, error in

    }
    locationManager.requestAlwaysAuthorization()
    locationManager.startMonitoringVisits()
    locationManager.delegate = self as? CLLocationManagerDelegate

    locationManager.distanceFilter = 35
    locationManager.allowsBackgroundLocationUpdates = true
    locationManager.startUpdatingLocation()
    return true
  }

}
extension AppDelegate: CLLocationManagerDelegate {
  func locationManager(_ manager: CLLocationManager, didVisit visit: CLVisit) {
    // create CLLocation from the coordinates of the CLVisit
    let clLocation = CLLocation(latitude: visit.coordinate.latitude, longitude: visit.coordinate.longitude)
    AppDelegate.geoCoder.reverseGeocodeLocation(clLocation) { placemarks, _ in
      if let place = placemarks?.first {
        let description = "\(place)"
        self.newVisitReceived(visit, description: description)
      }
    }

  }

  func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
      // 1
      guard let location = locations.first else {
        return
      }

      // 2
      AppDelegate.geoCoder.reverseGeocodeLocation(location) { placemarks, _ in
      if let place = placemarks?.first {
        // 3
        let description = "Fake visit: \(place)"

        //4
        let fakeVisit = FakeVisit(
          coordinates: location.coordinate,
          arrivalDate: Date(),
          departureDate: Date())
        self.newVisitReceived(fakeVisit, description: description)
      }
    }
  }
  // MY issue is here in the line with the ** before and after it
  func newVisitReceived(_ visit: CLVisit, description: String) {
    let location = Location(visit: visit, descriptionString: description)
    **LocationsStorage.shared.saveLocationOnDisk(location)**

    // save location to the disk

    // Get location description

    let content = UNMutableNotificationContent()
    content.title = "New Journal Entry Looks like you are working through the following tutorial

Just over half way through the tutorial there is a section and code block that looks like this:

Saving Records on Disk

Open LocationsStorage.swift. At the bottom of the class, add the following function:

func saveLocationOnDisk(_ location: Location) {
  // 1
  let encoder = JSONEncoder()
  let timestamp = location.date.timeIntervalSince1970

  // 2
  let fileURL = documentsURL.appendingPathComponent("\(timestamp)")

  // 3
  let data = try! encoder.encode(location)

  // 4
  try! data.write(to: fileURL)

  // 5
  locations.append(location)
}
导入UIKit 导入核心定位 导入用户通知 @UIApplicationMain 类AppDelegate:UIResponder、UIApplicationLegate{ 变量窗口:UIWindow? 静态let geoCoder=CLGeocoder let center=UNUserNotificationCenter.current 让locationManager=CLLocationManager func应用程序uApplication:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplication.launchOptions键:任意]?=nil->Bool{ 让rayWenderlichColor=UIColorred:0/255,green:104/255,blue:55/255,alpha:1 uitabar.appearance.tintColor=rayWenderlichColor center.requestAuthorizationoptions:[.alert、.sound]{已授予,中有错误 } locationManager.requestAlwaysAuthorization locationManager.StartMonitoringVisitions locationManager.delegate=自我身份?CLLocationManagerDelegate locationManager.distanceFilter=35 locationManager.AllowBackgroundLocationUpdates=true locationManager.startUpdatingLocation 返回真值 } } 扩展AppDelegate:CLLocationManagerDelegate{ 职能地点经理\经理:CLLocationManager,didVisit访问:CLVisit{ //根据CLVisit的坐标创建CLLocation 让clLocation=CLLocationlatitude:visit.coordinate.lation,经度:visit.coordinate.longitude AppDelegate.geoCoder.ReverseGeocodeLocationAllocation{placemarks,u中 如果let place=placemarks?首先{ 让description=\place self.newVisitReceivedvisit,描述:描述 } } } func locationManager\uManager:CLLocationManager,didUpdateLocations位置:[CLLocation]{ // 1 防护装置位置=位置。首先是其他位置{ 回来 } // 2 AppDelegate.geoCoder.ReverseGeocodeLocation{placemarks,uu中 如果let place=placemarks?首先{ // 3 let description=假访问:\place //4 让假参观=假参观 坐标:location.coordinate, 到达日期:, 出发日期:日期 self.newVisitReceivedfakeVisit,描述:描述 } } } //我的问题在这里与**前后一致 func newVisitReceived_uu访问:CLVisit,描述:字符串{ let location=Locationvisit:visit,description字符串:description **LocationsStorage.shared.SaveLocationOnDisklLocation** //将位置保存到磁盘 //获取位置描述 let content=UNMutableNotificationContent
content.title=新日记账分录看起来您正在完成以下工作

本教程刚过一半,有一个部分和代码块如下所示:

在磁盘上保存记录

打开LocationsStorage.swift。在类的底部添加以下函数:


请确保您添加了此方法,并且在代码中使用了正确的名称来调用该方法

您的代码只有saveLocationOnDisk,但错误是关于saveCLLocationToDisk。对吗?我不熟悉名为LocationsStorage的任何内容,但函数名似乎不一致。@scriptable谢谢您,先生!这很有效非常完美-不确定我怎么会错过它