May 16

Today I will explain how we can play a sound when a button is pressed, in fact, what I will explain can be used in many other situations and not only for buttons, because what I will do is to create a SystemSoundID which is used, among another things, to play short (30 seconds or less) sounds. But as an example, I will use a button.

To be able to reproduce sounds we will need to add the AudioToolbox Framework to our project.

Imagine we have a UIViewController and the view it is controlling, add a UIButton to the view using Interface Builder or do it programmatically, as you like most. If you haven’t added yet the Framework to the project, do it now, once you have done it we have to import it to our view controller.

In the header file (.h) of our controller add a variable of type SystemSoundID and a method which will be called when the button is pressed.

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
 
@interface testKeyboardViewController : UIViewController <UITextFieldDelegate> {
 
	SystemSoundID buttonSoundID;
}
- (IBAction)buttonPressed;
 
@end

Now we need a sound file, with the sound we want, for example call it ButtonSound.caf, now, and in the viewDidLoad of our controller add the following lines to create the reference to our sound.

- (void)viewDidLoad {
    [super viewDidLoad];
	NSString *path = [[NSBundle mainBundle] pathForResource:@"ButtonSound" ofType:@"caf"];
	AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &buttonSoundID);	
}

As you can see in the code, we need the path for our file, if you have add the file to your group Resources in Xcode, the code above should work for you. Take a look at NSBundle if that doesn’t work to look for another method that allows you to find the path to the file.

With this we have the reference to the sound, now we only need to play it when we need, in this case, we want to play it when the button is pressed. Add to the method that is called when the button is pressed, the following lines

- (IBAction)buttonPressed {	
	AudioServicesPlaySystemSound(buttonSoundID);
}

Now you should be hearing the sound when you press the button.

When you don’t need anymore the sound, you can use the following function to remove the reference, for example in the viewDidUnload of our controller.

- (void)viewDidUnload {
	AudioServicesDisposeSystemSoundID(buttonSoundID);
}

I hope that this post is useful and now you are able to add all kind of short sounds to your application to give it a bit more of life.

VN:F [1.9.8_1114]
Rating: 5.0/5 (2 votes cast)
VN:F [1.9.8_1114]
Rating: +2 (from 2 votes)
Tagged with:
Apr 27

En este artículo vamos a explicar como encontrar el identificador (no confundirlo con el número de serie) del iPhone (iPod y iPad)  también conocido como “device id”.

Tenemos que seguir los siguientes pasos:

  1. Conectar nuestro dispositivo al ordenador (Mac o Windows).
  2. Abrir el iTunes.
  3. Seleccionar nuestro dispositivo en la lista de dispositivos.

    .
  4. Seleccionar la pestaña Resumen y hacer click sobre el texto “Número de serie”. Al hacer esto el número de serie cambiará y mostrará el identificador.

    Después del click en “Número de serie” debería ver el identificador:


Finalmente, si queremos copiar el identificador vamos al menú: Edición > Copiar (mientras el identificador este visible).

Si estamos en un sitio donde no tenemos acceso a nuestro ordenador pero si tenemos acceso a Internet podemos conectarnos a AppStore y descar una de las aplicaciones especializadas que nos muestran nuestro device id y permiten enviarlo fácilmente. Dos de esas aplicaciones son: Info – UDID y Info – UDID Sender.

Si tiene preguntas no dude en contactar con nosotros.

VN:F [1.9.8_1114]
Rating: 4.3/5 (9 votes cast)
VN:F [1.9.8_1114]
Rating: +1 (from 5 votes)
Tagged with:
Apr 27

In order to find your device id you have to:

  1. Connect the device to your computer (Mac or Windows).
  2. Open the iTunes.
  3. Select your device.

    .
  4. Go to summary tab and click on “Serial Number”. You’ll notice that the “Serial Number” changes to “Identifier”.

    After clicking on the “Serial Number” we must see something like this:

Finally if you want to copy the id: click on Edit > Copy (while the Identifier is visible).

If you haven’t access to your computer but you have Internet connection you can download some free specialized apps (Info – UDID or Info – UDID Sender) from AppStore which can provide you with your device id information.

VN:F [1.9.8_1114]
Rating: 3.4/5 (5 votes cast)
VN:F [1.9.8_1114]
Rating: +1 (from 1 vote)
Tagged with:
preload preload preload