Я создал собственное намерение Sirikit, в классе IntentHandler я не могу найти местоположение пользователя, где по умолчанию для местоположения задано значение «Всегда».пожалуйста, посмотрите на код.
import Foundation
import CoreData
import CoreLocation
class PhotoOfTheDayIntentHandler: NSObject, PhotoOfTheDayIntentHandling {
let context = CoreDataStorage.mainQueueContext()
var counter : DistanceEntity?
var locationManger = CLLocationManager()
func confirm(intent: PhotoOfTheDayIntent, completion: @escaping (PhotoOfTheDayIntentResponse) -> Void) {
completion(PhotoOfTheDayIntentResponse(code: .ready, userActivity: nil))
}
func handle(intent: PhotoOfTheDayIntent, completion: @escaping (PhotoOfTheDayIntentResponse) -> Void) {
self.context.performAndWait{ () -> Void in
let counter = NSManagedObject.findAllForEntity("DistanceEntity", context: self.context)
if (counter?.last != nil) {
self.counter = (counter!.last as! DistanceEntity)
let currentLocation: CLLocation = locationManger.location!
let greenLocation = CLLocation(latitude:self.counter!.latitude, longitude: self.counter!.longitude)
let distanceInMeters = currentLocation.distance(from: greenLocation) // result is in meters
debugPrint("distanceInMeters",distanceInMeters)
completion(PhotoOfTheDayIntentResponse.success(photoTitle: "\(distanceInMeters) Meter"))
completion(PhotoOfTheDayIntentResponse.success(photoTitle: "\(self.counter!.distance) Meter"))
}
}
}
}
, если я прокомментирую диспетчер местоположений, это вылетит.