create a directory to save recorded files on iphone using objective c - objective-c

I am letting user record audio from mic to .acc file
at the moment they are saved to default app document folder
in plist i enabled "supports opening documents in place"
Now in iPhones File App i can see my apps folder in Documents and also see and listen to the recorded .acc file
great... but...
Now the user can also see and then edit / mess with ini files and other files i dont really want them o see or edit etc...
So now this isnt a good solution.
So where do i save recorded audio so that users can still see them, find them on their phone, listen and share them with friends (without being to see the apps other files)?

For any files that don't need to change, just keep them as resources in your app bundle and load them from there at runtime.
For files that are generated at runtime (not at build-time) or config files that change, which you don't want to be exposed, put them in Application Support instead of in Documents.
In Objective-C:
NSArray * appSupportURLs = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory
inDomains:NSUserDomainMask];
In Swift:
let appSupportURLs = FileManager.default.urls(for: .applicationSupportDirectory,
in: .userDomainMask)
This Apple Developer video pretty much covers it: https://developer.apple.com/videos/play/tech-talks/204/

Related

How can a DCR file create a text file

I have just creating a game that is played on the web (with shockwave player DCR)
I wanted to make HIGHSCORE.txt lingo, for the game.
As for projector.exe: I can use getpref and setpref lingo command, no problem.
But for the game DCR on the web, the getpref and setpref seemed to be not working,
There's no highscore.txt created within the web folder. What should I do?
getpref() and setpref() do generally work well in Shockwave, I'm don't know what folder you are looking for the text file in but according to the Adobe docs here is where the text file is saved:
Windows Shockwave
..\Documents and Settings\\Application Data\Adobe\Shockwave Player \Prefs\
MAC Shockwave
~/Library/Application Support/Adobe/Shockwave Player/Prefs
setpref() can fail if the user is running in an environment with especially restrictive security settings but that is rare. Full docs here http://help.adobe.com/en_US/Director/11.5/UsingScripting/WSc3ff6d0ea77859461172e0811d64c1a1b3-7ecf.html

Objective C reading array from file fails on different locations

I am developing a mac app and I want to put my settings (array of strings) into a file. If that file exists in the same folder as the app it is read and it overwrites default settings.
No problems writing the file but when reading with code:
NSArray* settingsInput = [[NSArray alloc] initWithContentsOfFile:#"./SettingsFile"];
something strange happens. When running the app from XCode (the settings file is in the build/debug folder next to the app) settings are read without a problem. When I archive the app and run it from the desktop, the file cannot be loaded. Even when I copy the app from the build folder to the desktop it does not work.
What could be the reason for this kind of behaviour? How can I read this file?
It may be a better Idea to use the normal prefence system. NSUserDefaults.
There a couple of ways you can do it.
But the idea is to give your app a set of default preference which are registered for you in the correct domain and always with a fresh app.
Using the registerDefaults: from NSUserDefaults.
See Apples documentation NSUserDefaults and its #registerDefaults
But the one I would use is :
Copy a plist file into the supporting files in you Xcode project.
Making sure "Copy files into destination group's folder" is checked. And the "Add to targets is check also"
The plist file should contain your array of strings.
(I created mine. By duplicating another plist in my user preferences. Renaming it. Copying it to the project. Selecting it and editing it to how I needed it. Making sure I use the file menu ->'Save' to save the changes. )
Declare a NSUserDefaults * prefs;
Now in the - (id)init method for the app. you register the contents of the file as your default preferences.
- (id)init
{
self = [super init];
if (self) {
prefs = [NSUserDefaults standardUserDefaults] ;
NSString *registerDefaultsPlistFile= [[NSBundle mainBundle] pathForResource:#"registerDefaults" ofType:#"plist"];
[prefs registerDefaults:[NSDictionary dictionaryWithContentsOfFile: registerDefaultsPlistFile]];
}
return self;
}
You can later make a call to read these preferences.
NSLog(#" arrayOfStrings = %#", [prefs objectForKey:#"arrayOfStrings" ]);
These default preferences are NOT written to file/out unless you make a change to them. By written to file I mean to the applications preference file. Once you do make a change to them then they will be written out into the users preferences and those are what will be used from then on.
You should not rely on the current directory of the app. You should either read from the app bundle (see NSBundle class for get the correct path) or the app's document directory (see NSSearchPathForDirectoriesInDomains(NSDocumentDirectory ...).
The UNIX concept of the current working directory is not commonly used in Mac desktop applications. When launching an app through the Finder it's usually set to the root directory of the boot volume.
You should find another way to determine locations for your settings files. Good spots would be ~/Library/Preferences or ~/Library/Application Support/MyApp. You can get the absolute path to these directories using:
NSString *path = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomain, YES)[0];

path of suporting files in OS X program?

I need some help for my OS X program.
I need the URL of a file inside the supporting files.
I have an array in which I save URLs from images and add them to a table view and if no images are chosen I want to add a question mark image (it is called "bild.jpg")
This bild.jpg is inside the supporting files but for later use I can't just save the name of the image because the array stores also URLs.
I need to have the URL of that image in the supporting file because it's easier to use the array for image initialization.
Is there a function to get the path or is there a standard path to the supporting files? I already search on the net but couldn't find anything that could help.
You seem to be talking about the application bundle and its resources directory rather than, say, a subdirectory in ~/Library/Application Support/..., in which case you probably want something like:
[[NSBundle mainBundle] URLForResource:#"bild" withExtension:#"jpg"]
(See the documentation for NSBundle.)

iOS custom email attachment handling in iOS6

My app allows for a text file to be emailed to other users with or without images and audio. When there's no images or audio, then the app sends the text file "as is" with a custom extension (e.g. text.xxx). When there's audio and images, the app zips the text file along with the images and audio into a file named something like text.xxx.zip.
Prior to iOS 6 this worked fine. Pre iOS 6, the app was given the URL of the text.xxx.zip file. Now, with iOS 6, it appears that the file is already unzipped by Mail, and only the text.xxx is sent to the openURL handler.
Does anyone out there have any experience with this? Suggestions for a better approach? I'm thinking I'll need to come up with a unique extension for the zipped case...
So after pounding my head on this for the last 24 hours or so, this is what "solves" the problem:
1) Change any existing attachment filenames from test.xxx.zip to test.zip. It looks iOS6 Mail is assuming that anything of the form filename.xxx.zip, is really just a compressed version of filename.xxx. (Maybe that's a standard somewhere?) Also noted that if I changed the filename to test.yyy.zip it then said it couldn't open the attachment. (presumably since no one registered for the ".yyy" extension).
2) Rewrite code to not use .zip extension in the future to prevent similar issues.
I also discovered that for multiple document types (e.g., .xxx, .zzz) you must specify a different mime type for each in the UTI declaration - otherwise Mail appends the first UTI extension it finds to the object and then calls openURL. So, in other words, if you're set up to handle a flat file (.xxx) and a zip file (.zzz), but you use the same mime type (e.g. application/myappname) and "xxx" is defined first, when openURL is called for your file "test.zzz", it will actually pass it to openURL as "test.xxx".

Adding Help to a Cocoa App

I want to add a simple one-page HTML page help to my Cocoa app. Can you tell me how to do it? I assume I just have to throw in one lousy .html (and maybe one .css?) file somewhere into my Cocoa project in Xcode?
Creating Apple Help documents that are opened in the Help viewer is straightforward but you must follow the directions in the documentation exactly.
Help files are HTML but you need to place a couple of special tags in the page and name the files in a particular way.
It's all explained in the documentation.
Today I've been facing the same problem. I found no up-to-date howto so here is one of my own. Help is nicely working with this Step by Step to create Apple Help in your Cocoa Xcode Application.
If you only want a single HTML page and not a proper help file, you could add an HTML document and CSS file to your project. These will be copied to your application's Resources directory inside the app bundle when you compile the project. To load the document, you'll need to get its address. This is actually quite easy:
NSString *helpFilePath = [[NSBundle mainBundle] pathForResource:#"YourHelpDocumentHere" ofType:#"html"];
NSURL *helpFileURL = [NSURL fileURLWithPath:helpFilePath];
The resulting URL will be a file URL that a WebView can display inside your application, or you can pass it off to the operating system using NSWorkspace and it will be opened in the user's default web browser.