Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not export audiofiles via "open in:" from Voice Memos App

Tags:

ios

iphone

My app higly depends on audio files that can be exported from other apps into my app. The "Document Types" in my target´s "Info" pane are configured to accept and import 3 different types of audio files (mp3, m4a and aac) via "open in:" from another app´s share option. The export of audio from Mail or Dropbox into my app works but Voice Memos or even iMessage refuses to display my app as share option.

I have been discovered that exporting audio from Voice Memos into my app works via Dropbox. But that´s not a good way as it should work directly.

Has anybody an Idea what to do to get the audio export from Voice Memos working?

Thanks in advance, Paul

like image 662
ehrpaulhardt Avatar asked Dec 28 '15 15:12

ehrpaulhardt


2 Answers

I am sure a lot has changed since this question was posted, but here is how I managed to export audio files from the Voice Memo App to my app via the "copy to:" sharing option.

  • In XCode, under the info panel of my target I added the com.apple.m4a-audio Document Type and added Supports opening documents in place (set to YES) to the Custom iOS Target Properties (see image below)
  • In my AppDelegate I implemented application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool

And that was it. Now from the Voice Memo App on my device, if I press the "share" button on a memo I see "Copy to [my app]" among the list of options (might need to enable it via the last option "more")

Here is a picture of the changes required in the Target's info panel: changes in the Target's info panel

And a sample to code to play the selected Voice Memo in your own app right after pressing "Copy to [your app]" (to be implemented in your AppDelegate):

  import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    let engine = AVAudioEngine()
    let player = AVAudioPlayerNode()

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        return true
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
guard let copyURL = URL(string: "test.m4a", relativeTo: FileManager.default.temporaryDirectory) else {
            return false
        }
        engine.attach(player)
        engine.connect(player, to: engine.mainMixerNode, format: nil)

        do {
            // Copy voice memo to this app's temp directory
            try FileManager.default.copyItem(at: url, to: copyURL)
            // Create readable audio file from copied file
            let file = try AVAudioFile(forReading: copyURL)
            // "Load" the file into the player
            player.scheduleFile(file, at: nil, completionHandler: nil)
            try AVAudioSession.sharedInstance().setActive(true)
            try engine.start()
        } catch {
            print(error)
            return false
        }

        player.play()
        return true
    }

}

Note that this code is only meant to illustrate that the url of the Voice Memo is properly propagated to your app and how to copy the file to the temp directory. From there you probably want to pass it to the proper ViewController.

EDIT: changed the code to illustrate how to copy the file

like image 130
Stefano Bider Avatar answered Oct 17 '22 02:10

Stefano Bider


Not sure if this will help you and you may need to create a script to automate the function of copying to the clipboard but here you go..

When the send selection bar is on "More", press on "App" to reveal a list of applications that accept audio files. Simply select an application in the list to send the memo associated with the send screen to it.

Note that the "App" cell will only be visible if sending a single memo (and is not available when changing the "Auto send" setting).

It is also possible to copy the audio contained in a memo to the clipboard. Another application can then read the content of the clipboard to import audio. To copy audio to the clipboard make a long press on the name of a memo in the list of memos and press the "Copy" button that appears. If the "Copy" button does not appear, you are probably trying to copy a too big memo (you should not try to copy memos over 30MB).

like image 1
norcal johnny Avatar answered Oct 17 '22 01:10

norcal johnny