Post not yet marked as solved
Post marked as unsolved with 2 replies, 637 views
Hello Forum,I am developing an application for iPad - iOS 13, which should play videos over Airplay connected to an AppleTV depending on location.I encountered the problem that the CLLocationmanager stop calling update location with the error "location manager KCLErrorDomain code=0 error" after 1 to 3 update of location when connected to the apple tv.If the app runs without mirroring the location update works fine.Did someone had similar problems or could give a hint to me?Implementation of the second screen to show AVPlayer in AppDelegate:func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
print(connectingSceneSession.role.rawValue)
if "UIWindowSceneSessionRoleExternalDisplay" == connectingSceneSession.role.rawValue {
/*return UISceneConfiguration(name: "External Configuration", sessionRole: connectingSceneSession.role)*/
let scene = UIWindowScene(session: connectingSceneSession, connectionOptions: options)
let win = UIWindow(frame: scene.screen.bounds)
win.rootViewController = UIStoryboard(name: "External", bundle: nil).instantiateViewController(identifier: "external") as! ExternalViewController2
win.windowScene = scene
win.isHidden = false
secondWindow = win
}
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}Viecontroller with CLLocationManager to control the video playback:import UIKit
import CoreLocation
import MobileCoreServices
class routeDisplayViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate, CLLocationManagerDelegate {
@IBOutlet weak var stageTable: UITableView!
@IBOutlet weak var routeName: UILabel!
var currentRoute : route?
let fileManger = FileManager.default
var videoURL: NSURL? = nil
var locMan : CLLocationManager? = nil
var currentRow : Int = 0
var secondWindow : UIWindow?
var sScreeView : UIView?
var extVC : ExternalViewController?
override func viewDidLoad() {
super.viewDidLoad()
currentRoute = (UIApplication.shared.delegate as! AppDelegate).tramRoutes[(UIApplication.shared.delegate as! AppDelegate).routeInd]
locMan = CLLocationManager()
locMan!.requestAlwaysAuthorization()
locMan!.requestWhenInUseAuthorization()
locMan?.pausesLocationUpdatesAutomatically = false
locMan?.delegate = self
stageTable.delegate = self
stageTable.dataSource = self
if UIScreen.screens.count > 1 {
extVC = ((UIApplication.shared.delegate as! AppDelegate).secondWindow?.rootViewController as? ExternalViewController2)?.externPlayerController
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (currentRoute?.stages.count)!
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = stageTable.dequeueReusableCell(withIdentifier: "stageCell", for: indexPath)
cell.textLabel?.text = currentRoute?.stages[indexPath.row].spotName
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
currentRow = indexPath.row
}
func moveTableToCell (rowIndex: IndexPath) {
stageTable.scrollToRow(at: rowIndex, at: .middle, animated: true)
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let stage = currentRoute?.stages[currentRow]
let spot = (UIApplication.shared.delegate as! AppDelegate).routeSpots[stage!.spotName]
let target = CLLocation(latitude: Double(exactly: spot!.latitude)!, longitude: Double(exactly:spot!.longitude)!)
guard let locValue: CLLocation = manager.location else {return}
print(locValue)
routeName.text = "\(locValue.coordinate.latitude) \(locValue.coordinate.longitude)"
let dis = locValue.distance(from: target)
if dis < Double(exactly:stage!.distance)! {
if !(extVC!.isPlaying!) {
extVC?.playVid(vidName: stage!.vidFileName, preventFromPlaying: true)
}
stageTable.selectRow(at: IndexPath(row: currentRow, section: 0), animated: true, scrollPosition: .middle)
if currentRow+1 < stageTable.numberOfRows(inSection: 0) {
currentRow+=1
}
}
}
func startLocationDetection() {
if CLLocationManager.locationServicesEnabled() {
locMan!.delegate = self
//locMan!.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locMan!.startUpdatingLocation()
}
}
func locationManagerDidPauseLocationUpdates(_ manager: CLLocationManager) {
print("ex pause")
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("ex error: \(error)")
}
func locationManager(_ manager: CLLocationManager, didFinishDeferredUpdatesWithError error: Error?) {
print("deffered ex error: \(String(describing: error))")
}
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
print("loc stat: \(status)")
}
//MARK: BtnActions
@IBAction func back(_ sender: UIButton) {
performSegue(withIdentifier: "backStartView", sender: nil)
}
@IBAction func startRoute(_ sender: UIButton) {
startLocationDetection()
extVC?.playVid(vidName: currentRoute!.startVideo, preventFromPlaying: true)
}
@IBAction func playWaitVid(_ sender: Any) {
/*extVC?.playVid(vidName: currentRoute!.waitVideo, preventFromPlaying: false)*/
}
}