Michael Jajou
Michael Jajou

Reputation: 392

Using NSTemporaryDirectory to write video files

In my app, users are allowed to record videos up to 20 minutes long. When I start the AVCaptureSession, it writes the movie file to a temporary directory. I was just wondering if this was a bad habit and using a temporary directory is not good for long videos.

If this is not a good method to do so, where else should I write the videos? This is what my function looks like.

func videoFileLocation() -> String {
    let dateFormatter = DateFormatter()
    dateFormatter.dateStyle = .long
    dateFormatter.timeStyle = .long
    let date = dateFormatter.string(from: Date())

    return NSTemporaryDirectory().appending("video\(date)File.mov")
}

Upvotes: 1

Views: 290

Answers (1)

Return Zero
Return Zero

Reputation: 434

you can use Document directory .

func videoFileLocation() -> String {
    let dateFormatter = DateFormatter()
    dateFormatter.dateStyle = .long
    dateFormatter.timeStyle = .long
    let date = dateFormatter.string(from: Date())
    let documents = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String
    let writePath = documents.stringByAppendingPathComponent("video\(date)File.mov")
    return writePath
}

Upvotes: 1

Related Questions