How to add current timestamp to camera in ios app

enter image description here

Something like that. I want to add the current timestamp when the recording is done in the video and save to the camera roll.

** Note **: I successfully added the current location and timestamp to AVVideoPreviewLayer, but it is static after exporting the video, shows static time, does not show the current timestamp

+5
source share
2 answers

Try creating a preview layer: UIView with the components that you want to have on the camera.

Add this layer to the current AVCaptureVideoPreviewLayer session.

This link can help you solve your problem.

Adding objects through viewing the camera in the application (Swift 3) not under the camera?

+1
source

I tried something. I think you want to get latitude, longitude and timestamp.

Below you will find an example for latitude and longitude.

import UIKit import CoreLocation class ViewController: UIViewController, CLLocationManagerDelegate { var locationManager: CLLocationManager! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func showLocation(_ sender: Any) { locationManager = CLLocationManager() locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.requestAlwaysAuthorization() if(CLLocationManager.locationServicesEnabled()){ locationManager.startUpdatingLocation() } locationManager.stopUpdatingLocation() } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { let userLocation:CLLocation = locations[0] as CLLocation print("user latitude = \(userLocation.coordinate.latitude)") print("user longitude = \(userLocation.coordinate.longitude)") } func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { print("Error \(error)") } } 

To get the current time, you can use something like this:

 let date = NSDate() print(date) 

The result for both consoles should look something like this:

 2017-12-17 21:45:39 +0000 user latitude = 37.3322499 user longitude = -122.056264 

(Time looks like this in my example, because I'm from the EU, but you can convert it to what you want)

You can add this to a separate view and bring it to the forefront with

 view.bringSubview(toFront: YourView) 

I hope this will be helpful!

+1
source

Source: https://habr.com/ru/post/1273949/


All Articles