Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add current timestamp in camera in ios app

enter image description here

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

**Note **: I have successfully added current location and timestamp in AVVideoPreviewLayer but it is static after exporting video is show static time does not show running timestamp

like image 710
Ajharudeen khan Avatar asked Oct 29 '22 22:10

Ajharudeen khan


2 Answers

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

Add this layer to currently running session of AVCaptureVideoPreviewLayer.

This link might help you to achieve your problem

Adding objects over camera view in app (Swift 3) not under camera view?

like image 67
sandeep.chandekar Avatar answered Nov 15 '22 07:11

sandeep.chandekar


I tried something out. I guess you want to get latitude, longitude and the timestamp.

You find an example for latitude and longitude below.

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 in console should look something like this:

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

(The time looks like this in my example because im from EU but you can convert it to what you want)

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

view.bringSubview(toFront: YourView)

I hope this is helpful!

like image 30
Philip Dz Avatar answered Nov 15 '22 06:11

Philip Dz