0

I'v built an app that lets the user record their voice and save the file in their local Document Directory (They can create/save as many audio files they choose too).

But recently Iv into the problem where after a certain amount of saves it seems my function to save does not work on my simulator until i reset the simulator data. Then it will work again.

I also tried it on my own iPhone..it was working where the user can create/save and listen to their audio but now it wont let them listen to it but saving works fine from what I can tell.

Here are the related codes!

func tableView(tableView: UITableView,
               editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    let play = UITableViewRowAction(style: .Default, title: "Play", handler: { (action, indexPath) in
        self.tableView.dataSource?.tableView?(
            self.tableView,
            commitEditingStyle: .Delete,
            forRowAtIndexPath: indexPath
        )



        let dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
        dispatch_async(dispatchQueue, {

            let url = self.sharedRec.audioDic[indexPath.row]["audioURL"] as String!
            let kingURL = "\(url)"
            print(kingURL)
            if let data = NSData(contentsOfFile: kingURL) {
                do {
                    print("PLAYING AUDIO WORKED!") // NOT WORKING ANYMORE
                    self.audioPlayer = try AVAudioPlayer(data: data)
                    self.audioPlayer.delegate = self
                    self.audioPlayer.prepareToPlay()
                    self.audioPlayer.play()

                    // Progress View Code

                    NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(RecordPanel.updateAudioProgressView), userInfo: nil, repeats: true)

                } catch {
                    print("ERROR BOY \(kingURL)")
                    print("\(error)")
                }
            }
        })

        print("I PLAYED")

        return
    })
    let pause = UITableViewRowAction(style: .Default, title: "Pause", handler: { (action, indexPath) in
        self.tableView.dataSource?.tableView?(
            self.tableView,
            commitEditingStyle: .Delete,
            forRowAtIndexPath: indexPath
        )

        if let player = self.audioPlayer {
            player.pause()
        }



        return
    })
    let delete = UITableViewRowAction(style: .Default, title: "Delete", handler: { (action, indexPath) in
        self.tableView.dataSource?.tableView?(
            self.tableView,
            commitEditingStyle: .Delete,
            forRowAtIndexPath: indexPath
        )

        let uid = NSUserDefaults.standardUserDefaults().valueForKey("uid") as! String // uid
        DataService.dataService.deleteAudio(uid, project: self.sharedRec.projectName, vocalString: self.sharedRec.audioString )

        let currURL = self.sharedRec.audioString
        let url = "\(currURL).caf"

        //Document Directory
        let dirPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
        // Full File to Delete Location
        let fileURL = dirPath.stringByAppendingPathComponent(url)
        // This is to print out all directory files
        let documentsUrl =  NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!

        do {
            try NSFileManager.defaultManager().removeItemAtPath(fileURL)
            print("file deleted \(fileURL)")
            let directoryContents = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(documentsUrl, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions())
            print(directoryContents)
        } catch {
            print("error")
        }

        return
    })
brkr
  • 1,208
  • 1
  • 12
  • 18
  • As per disclose on official apple websites, there is storage limit of Document Directory is up to 2 GB in devices only. – Jigar Tarsariya May 06 '16 at 05:17
  • Possible duplicate of [iOS Documents Directory size limit](http://stackoverflow.com/questions/13154160/ios-documents-directory-size-limit) – Jigar Tarsariya May 06 '16 at 05:18
  • There is no limit other than the user's device actual space available – Leo Dabus May 06 '16 at 07:15
  • @LeoDabus Would you know what would cause my actual iphone from not being able to play the recorded audio and the simulator can play it successfully? Is it better if i save the audio in AWS or somewhere besides the user's phone? – brkr May 06 '16 at 18:06

0 Answers0