2

I am listing my audio into a tableView cell with trailing swipe for delete and share button. Here, I have to do two things:

  1. I need to convert audio data to file
  2. Share the file to another application like Gmail, etc.

Code:

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete {
        if let context = (UIApplication.shared.delegate as? AppDelegate)?.persistentContainer.viewContext {
            let sound = sounds[indexPath.row]
            context.delete(sound)
            getSound()
        }
    }
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let sound = sounds[indexPath.row]
    if let audioData = sound.audioData {
        audioPlayer = try? AVAudioPlayer(data: audioData)
        audioPlayer?.play()
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
pastelsdev
  • 145
  • 1
  • 14
  • and what is the problem to do this? – canister_exister Nov 12 '18 at 15:16
  • I have added share button in each cell. If I click share button I need to share audio file to other application like gmail,etc,...I searched but I didn't get audio data to file conversion and attachment within other apps. Please help me @canister_exister – pastelsdev Nov 12 '18 at 17:43
  • https://stackoverflow.com/a/51783763/4311935 – canister_exister Nov 12 '18 at 18:01
  • https://stackoverflow.com/questions/41263742/how-do-i-share-an-audio-file-in-an-app-using-swift-3 – canister_exister Nov 12 '18 at 18:01
  • Thank you @canister_exister. If I use that I am getting null value crash at let activityItem = URL.init(fileURLWithPath: Bundle.main.path(forResource: "fileName", ofType: "mp3")!) here. Files I am storing into coredata and local document directory. – pastelsdev Nov 12 '18 at 18:05

0 Answers0