Save audio file to a user-friendly location swift 3 avfoundation - ios

I am writing a simple recorder application which can record/play audio (via. AVFoundation) and save it locally to the iOS device. I've found several sources de
Initially, I would have liked to send out multiple of these saved audio files via email (MessageUI) such as with this simple example: https://gist.github.com/kellyegan/49e3e11fe68b5e6b5360 - though recently I have felt maybe I should forego this in favor of simply saving to the device and allowing the user to send out the file somehow.
Considering this, I feel it might be best to try to save the audio file to a more user-friendly destination. Is there any way I can save these files locally that might allow the user to 'share' them via iOS (outside of my application)? Maybe even to their iTunes library? This seemed promising: iOS - Save audio files to iTunes music library - but looks like the solution provided is actually for saving images to the 'photo album'
When I print the audio file's URL I get something like
'file:///var/mobile/Containers/Data/Application/AA3E5177-A8C8-4FFA-8EBC-85A2A6844A88/Documents/recording-2017-03-06-12-54.m4a'
I am a serious noob w/ Swift 3 and definitely with AVFoundation - I'd really appreciate any and all help/advice. Thanks in advance!

The URL 'file:///var/mobile/Containers/Data/Application/AA3E5177-A8C8-4FFA-8EBC-85A2A6844A88/Documents/recording-2017-03-06-12-54.m4a' may look elaborate to you, but in fact it is totally "user-friendly". It's a file in the app's Documents folder! Nothing could be simpler than that.
The URL in question would never be seen by the user; in fact, it won't even be the same between runs of your app.
Your app can certainly provide interface for the user to select one or more files, and can make them available for sharing out by means of UIActivityViewController or UIDocumentInteractionController.
You might also want to look into UIDocumentPickerViewController or even https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/FileProvider.html

iOS apps are heavily sandboxed. The app's Documents directory (at the path you posted) is the typical place for files like this. You can enable file sharing from the app in iTunes (on the user's computer) by adding the UIFileSharingEnabled key (Application supports iTunes file sharing) to your Info.plist file.
The typical way to enable sharing within the app is by using UIDocumentInteractionController or UIActivityViewController.

Related

Audiio fiiles inside an iOS application

Is there a way inside an iOS Swift app of mine, to access the sound files I already have available in my itunes library on the same device?
Browsing the net I came accross something called File-Sharing and the UIFileSharingEnabled key, but that does not seem to be quite what I am looking for.
The files? I’m not sure.. if so only those you downloaded or bought on iTunes. For access to Apple Music you probably want to look into MusicKit.
However, there’s a way to get MediaItems via MPMediaPickerController (docs)

General iOS File Finder

In my App I would like to import various document types (video, audio, photo's, pdf and text). I can use UIImagePickerController for the photo's and videos. I can use UIDocumentPickerViewController to get all file types from an iCloud drive - but this does not seem to find any files I have created on this device (and not added to iCloud). I feel like I am missing something fundamental. NSOpenPanel is there for OSX, is there nothing equivalent for iOS?
UIDocumentPickerViewController can only access files in iCloud or a similar service (eg DropBox). There is no way to access files outside your app's sandbox. They must first be moved (or copied) to iCloud.

How to export downloaded audio file(from within app folder) to user accessible music folder in IOS

I am using Xamarin to develop an IOS app. Here the user has an option to download audio files to the document folder within the app, and play it later on.
But i would like to provide an option for the user to access it in music folder or somewhere else, so that user does not have to come back to app to listen it.
Like we save images to camera roll, can we save mp3 or any other audio file to default music folder in IOS. Any solution or ideas using xamarin or xcode are welcome.
Note: I already know about File Sharing with itunes, i am looking for something else explained above.
As I know this isn't possible due to the limitations within iOS

Writing to a file in my iOS app

I have an app that downloads files that need to be edited and submitted back to the server through the app. These files could be anything, but are most likely to be .docs. I want to be able to open and edit these files in another app on the device, such as a .doc editor.
I've been able to get this functionality to work in similar Android and Chrome apps, but I'm very new to iOS so I'm not sure what my options are.
Is there a way to give permission for another app to edit a file that is in my app's sandbox? If not, is there a way to get the file back for submittal (like finding it through a file explorer launched through my app - similar to an 'Open..." file explorer dialog used in Windows/Mac OS/Chrome)? Am I going to have to create a way for the editor app to share the edited file back to my app?
Thanks in advance for your help!
To manage the file and the paths take a look at the documentation for NSFileManager:
https://developer.apple.com/LIBRARY/mac/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html
I usually write using NSFileHandle for reading and writing:
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSFileHandle_Class/Reference/Reference.html
Hope this helps.
iOS8 will provide methods to allow apps to co-operate with "extensions".
See "Creating Extensions for iOS and OS X, Part 1 & 2` in the WWDC14 videos.
Also see the Apple "App Extension Programming Guide".
I ended up sending the file to a 3rd party app for editing and then sending the file back from the 3rd app to my app.

How can you import text files into an iPad application?

For a school project, I am writing an iOS iPad application in which the user is capable of inputting sentences into core data that are used elsewhere in the system; however, my professor has now asked for another feature in which the user is capable of somehow entering sentences from some other interface than the iPad's keyboard. For instance, the most desirable solution is to be able to write sentences into text files and import them into the application through iTunes.
I have seen a few different apps capable of receiving files through iTunes, such as the VLC app in which the user can place videos into the VLC app's video storage. This allows VLC to then load the videos. I'm wondering if there is a good way or even if it's possible to do this with text files in my app, so that I may then read them into core data.
Thanks,
Chris
This is possible... First of all you need to add a value to your info.plist file which enables iTunes file sharing (like with VLC etc.) "UIFileSharingEnabled -> YES"
Then you can store files through iTunes. These files are put into your applications "Documents" - directory... When launching your application, you will need to check if new files are available and handle these changes...
You can also add document types / extensions, so that when you are sent an email with a txt file, it can be opened with your application. How do I register a custom filetype in iOS

Resources