Export audio files via “open to:” from Voice Memos application

I have the same question as “Paul” posted here: It is not possible to export audio files via “open to:” from the Voice Memos application - there are no answers to this topic yet.

Essentially, I'm trying to make it simple: After recording a voice reminder in iOS, I select "Open with" and from the pop-up that appears, I want to be able to select my application.

I tried everything I could think of and experiment with LSItemContentTypes without success.

Unfortunately, I do not have enough reputation to comment on the existing post above, and I am very desperate for a solution to this. Any help is greatly appreciated, even just to know if it is feasible or not.

Thank!

+4
source share
1 answer

(http://www.theappguruz.com/blog/share-extension-in-ios-8), , , ( , Action) . , . - ( "" ) - ; , , , .

  • , File > New > Target... Xcode. , " ", " " "".

. " ", . -.

  1. " :" Action, MyActionExtension. , " :" " ", Dropbox. (ActionViewController) (Maininterface.storyboard). .

  2. "". " MyActionExtension"? ". " ", . , .

  3. "MyActionExtension" (Cmd-0), , ActionViewController Info.plist. . ...

  4. . " :". " " "". (, , , , .) ( ) . "-" . " ", , ( ) . , "" "On". , "". , . .

  5. ActionViewController.swift, :

6. AVFoundation AVKit :

// the next two imports are only necessary because (for our sample code)
// we have chosen to present and play the audio in our app extension.
// if all we are going to be doing is handing the audio file off to the
// containing app (the usual scenario), we won't need these two frameworks
// in our app extension.
import AVFoundation
import AVKit

6. override func viewDidLoad() {...} :

override func viewDidLoad() {
  super.viewDidLoad()

  // Get the item[s] we're handling from the extension context.

  // For example, look for an image and place it into an image view.
  // Replace this with something appropriate for the type[s] your extension supports.

  print("self.extensionContext!.inputItems = (self.extensionContext!.inputItems)")

  var audioFound :Bool = false
  for inputItem: AnyObject in self.extensionContext!.inputItems {
    let extensionItem = inputItem as! NSExtensionItem
    for attachment: AnyObject in extensionItem.attachments! {
      print("attachment = \(attachment)")
      let itemProvider = attachment as! NSItemProvider
      if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeMPEG4Audio as String)
        //|| itemProvider.hasItemConformingToTypeIdentifier(kUTTypeMP3 as String)
        // the audio format(s) we expect to receive and that we can handle
      {
        itemProvider.loadItemForTypeIdentifier(kUTTypeMPEG4Audio as String,
            options: nil, completionHandler: { (audioURL, error) in
          NSOperationQueue.mainQueue().addOperationWithBlock {

            if let audioURL = audioURL as? NSURL {

              // in our sample code we just present and play the audio in our app extension
              let theAVPlayer :AVPlayer = AVPlayer(URL: audioURL)
              let theAVPlayerViewController :AVPlayerViewController = AVPlayerViewController()
              theAVPlayerViewController.player = theAVPlayer
              self.presentViewController(theAVPlayerViewController, animated: true) {
                theAVPlayerViewController.player!.play()
              }

            }
          }
        })

        audioFound = true
        break
      }
    }

    if (audioFound) {
      break  // we only handle one audio recording at a time, so stop looking for more
    }
  }
}

6. , . , , AVPlayerViewController, . , print(), , , :

self.extensionContext!.inputItems = [<NSExtensionItem: 0x127d54790> - userInfo: {
    NSExtensionItemAttachmentsKey =     (
        "<NSItemProvider: 0x127d533c0> {types = (\n    \"public.file-url\",\n    \"com.apple.m4a-audio\"\n)}"
    );
}]
attachment = <NSItemProvider: 0x127d533c0> {types = (
    "public.file-url",
    "com.apple.m4a-audio"
)}
  1. Info.plist :

7. Bundle display name , (MyActionExtension ). Save to MyApp. ( Dropbox Save to Dropbox.)

7b. CFBundleIconFile String (2- ) MyActionIcon . 5 . : MyActionIcon.png, MyActionIcon@2x.png, MyActionIcon@3x.png, MyActionIcon~ipad.png MyActionIcon@2x~ipad.png. ( 60x60 iphone 76x76 ipad. - , , RGB .) , .

7. - NSExtension > NSExtensionAttributes > NSExtensionActivationRule - , TRUEPREDICATE. , , , PDF .., .

. , . ( , .) (http://www.theappguruz.com/blog/ios8-app-groups) .

  1. . Project Navigator (Cmd-0) , . , "", "On". "+", , group.com.mycompany.myapp.sharedcontainer. ( group. , , DNS- DNS.)

  2. , , (group.com.mycompany.myapp.sharedcontainer).

  3. URL- . ActionViewController.swift , , AVPlayerViewController :

    let sharedContainerDefaults = NSUserDefaults.init(suiteName:
        "group.com.mycompany.myapp.sharedcontainer")  // must match the name chosen above
    sharedContainerDefaults?.setURL(audioURL, forKey: "SharedAudioURLKey")
    sharedContainerDefaults?.synchronize()
    
  4. , URL- , :

    let sharedContainerDefaults = NSUserDefaults.init(suiteName:
        "group.com.mycompany.myapp.sharedcontainer")  // must match the name chosen above
    let audioURL :NSURL? = sharedContainerDefaults?.URLForKey("SharedAudioURLKey")
    
  5. , , NSTemporaryDiretory(). (http://www.atomicbird.com/blog/sharing-with-app-extensions) , , NSFileCoordinator.

:

+4

All Articles