How do I trigger sound alert in OSX using Cocoa? - cocoa

When Finder finishes copying of files then it triggers a sound alert. How can I do that from my app?
Please note that it is not the same as simply playing a sound. I am from Windows background so I am assuming that OSX allows users to configure notification sound from some central location. So, if the user chooses a different sound for an event then that API should play that new sound. This way I can make my app gel into the system and it will be able to alert the user using sound which the user is familiar with.

Answering my own question.
Found a good guide on this - System Sounds in Cocoa (wayback machine archive).
Official guide - Introduction to Sound Programming Topics for Cocoa.
Official NSSound reference.
Update
Additional notes
The system alerts are the ones which user can configure, others like emptying recycle bin, sound made when copying files are not.
NSBeep is the simplest way to trigger the alert sound which notifies the user of an error. Other sounds are available at the following locations in Lion.
/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds
For other user interface sounds check the Resources folder under related packages of the core applications. These application packages can be found in /System/Library/CoreServices/.
So, for example if you want to play the move to recycle bin sound then use the following code.
NSSound *systemSound = [[NSSound alloc] initWithContentsOfFile:#"/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/dock/drag to trash.aif" byReference:YES];
if (systemSound) {
[systemSound play];
}
Caveats
The name and path of the sound files may change at anytime. In fact the location of SystemSounds before Lion was /System/Library/Components/CoreAudio.component/Contents/Resources/SystemSounds.

You should also check this guide http://cocoathings.blogspot.com/2013/01/playing-system-sounds.html

NSSound(named: "Funk")?.play()

Related

User preferences are not saved from XPC service

In my main app bundle I have supporting XPC service included. App is sandboxed and everything works quite fine, except that when I call [[NSUserDefaults standardUserDefault] setObject:forKey:] method and than - synchronize method from the XPC service app, preferences are not written and data cannot be retrieved next time I need it.
I didn't find anything related to this problem in Apple's documentation, except that the sandboxed app cannot access preferences of other apps. That's all right, I don't need it. XPC service has its own container in ~/Library/Containers, where it should be able to store its own data, I'd suppose. But obviously it's not the case for some reason.
I probably missed something, but cannot find what. Is there anything special which needs to be done (adding some entitlement or so) in order to make this work?
Thanks for any tips.
I believe you'll need to use Group Containers to share the preferences and I have achieved something similar (a non-UI LSUIElement app sharing preferences with its conventional Preferences app countpart) using RMSharedPreferences.

Lower security setting dialog after changing sandbox settings

I am developing an app which plays midi files in Mac.
When I activated sandboxing I couldn't hear any midi playback, after googling a bit I found out that I need to add some things in my entitlements.plist file,
So according to one forum which I saw, I added
com.apple.security.temporary-exception.audio-unit-host
I get a dialog box asking me to lower security settings every time I run the app on any mac. This is not desirable, how can i disable it?
The behavior you see is described in TN 2247 by Apple. It looks like you have at least one Audio Component that isn't suitable for sandbox. But probably not the one playing MIDI.
https://developer.apple.com/library/mac/technotes/tn2247/_index.html

How to make an ipad app impossible to close

I am programming an app for an experiment by the University of Queensland Psych Department. The app needs to be impossible to exit, or at least it would be preferable if it were impossible to exit. This is not a virus- it is for an experiment with the Grute Eylandt Aborigines. Anyways, do any of you guys have any idea how to set the app to be impossible to exit, or even better, to set it so that you have to enter a password to exit it? Furthermore, on a separate subject, do you guys have any idea how I can save the information in the app to the iPhone? This app will not go through the App Store so it does not need to follow App Store rules. Therefore, if there was a way to save "Button (whatever button it is) pushed at (time and date)" to the notes section of the iPhone every time a button was pushed in the app, and/or to save audio recorded using the AudioToolbox framework to the actual iPod library, that would be fantastic. Otherwise I would have to make some sort of db or plist file to save everything with if-then statements, I think. Thank you!
Check-out iOS 6 Accessibility feature:
It allows a parent, teacher, or administrator to limit an iOS device
to one app by disabling the Home button, as well as restrict touch
input on certain areas of the screen
Put the device in a "kiosk" case so keep the home button from being pressed. For storing the data to the device, if it is a small amount of data, use NSUserDefaults, if this will be a large amount of data, I would lean more toward Core Data
Easiest solution on the market -- MOKIMOBILITY has developed software that allows you to lock the home button. It is Mobile Device Management software with a full range of security features. It essentially locks down your iPad so the user is only able to use what you what them to use. It is called +MDM www.mokimobility.com The software can be managed mobile-y from a central interface. Slick software.

How to implement "Open With" contextual menu in OS X

Apps in OS X that can open files to launch their respective applications often let the user choose the app that'll open the file. An example is the Finder.
I am still unclear about what's the best solution to implement this. The challenges are performance and showing the app's icon.
First, to get the list of apps, I found only LSCopyApplicationURLsForURL().
The major difficulty for me now is to get the app icons. All I have is the URLs (paths) to the apps. The only way I know of to get the icons would be to create a CFBundle object and then read the app's plist to get the icon data. But that appears to invole lots of disk access, and I could imagine it'll be quite inefficient if the app is located on a remote file server.
I believe that there's also a cached database about the apps, which includes icons and display names (without extension), and such. But where is the API for that?
Note: The app is Carbon based, but I can make use of Cocoa (NS...) functions if necessary. Also, Support for 10.5, even 10.4, would be appreciated.
Alright. I solved it eventually.
I now use the Carbon function GetIconRefFromFileInfo(), which still works in Lion, though it's marked deprecated/obsolete.
I had also tried to use QLThumbnailImageCreate(), but that didn't get me any results, oddly. No idea what I did wrong.
For Cocoa apps, [[NSWorkspace sharedWorkspace] iconForFile:path] can be used (thanks to C. Grunenberg of DevonTechnologies for this tip, where it's used with EasyFind).

simple record and play application!

I am trying to make a simple application which will store the sound said by user , say on click of record button and will play it back to him/her , say on click of play button.
Can anyone suggest me some appropriate way to do this ??
Thanks,
Miraaj
You can use QuickTime Kit's capture APIs to record a movie of the audio, and QTMovie (from the same framework) to convert it to a more conventional format for audio files and to play back both the intermediate file and the converted file.
There used to be a QuickTime Kit Programming Guide, but it didn't cover capturing and is now gone from developer.apple.com. You should file a bug against the docs.
This answer will work in a Cocoa (Mac) app. If you meant to ask about the iPhone, you should re-tag your question, as the solution will be completely different for a Cocoa app vs. a Cocoa Touch (iPhone) app.
I used direct sound to create an entire internet phone application a few years ago. Your question is far simpler, you won't have to deal with the circular buffer as critically. Direct sound is pretty main stream and you can find a lot of help with it in forums, and it's free!

Resources