my aap crash on ios 7 when clicking on back button - objective-c

-(IBAction)Back:(id)sender{
NSString *path = [NSString stringWithFormat:#"%#%#",
[[NSBundle mainBundle] resourcePath],
#"/Dtmf-star.wav"];
//declare a system sound id
SystemSoundID soundID;
//Get a URL for the sound file
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
//Use audio sevices to create the sound
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
//Use audio services to play the sound
AudioServicesPlaySystemSound(soundID);
[Buttonback setImage: nil forState:UIControlStateNormal];
int size = [PhoneUrl length];
if (size>0) {
PhoneUrl = [PhoneUrl substringToIndex:size-1];
}
dspText.text = PhoneUrl;
}
this i have done..i am able to delete one digit but if there is more than one digit application get crash...
It is working fine in ios6.

Unless you post almost the complete code, these kind of problems are really hard to solve for us. But it is propably a good idea to run the program in combination with a debug function monitoring the memory, since your problem most likely has something to do with that.

Related

Memory leak in AudioServicesPlaySystemSound using ARC

I would need some help solving this memory leak problem. I am using ARC.
The potential leak is on this line:
NSURL *aFileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
Here is the code:
// === Check if the game should play sound === //
if (sound == YES) {
//==== PLAY THE LOOSING SOUND ====//
// Form a URL to the sound file, which in init using the Path
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *filePath = [mainBundle pathForResource:#"wrong2" ofType:#"wav"];
NSURL *aFileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
// Create a sound ID,
SystemSoundID myID;
// Register the sound
AudioServicesCreateSystemSoundID((__bridge_retained CFURLRef)aFileURL, &myID) ;
// Play the sound!
AudioServicesPlaySystemSound(myID);
}
Replace __bridge_retained by __bridge.
__bridge_retained would mean that you transfer the ownership of aFileURL to AudioServicesCreateSystemSoundID() and that function would have to release it (which it doesn't).
And I think you should also call
AudioServicesDisposeSystemSoundID(myID)
when the sound object is no longer needed.
Tip: When the static analyzer shows the "Potential leak" warning, click on the blue icon to the left of the warning and you will see detailed information about the problem.

xcode objective c - when I call 2 methods - only the last called method runs and first one is skipped

-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
[self NextHeading]; // this plays an mp3 file
[self NextHeadingMeaning]; // this plays an Mp3 file
}
Only [self NextHeadingMeaning] method is called and NextHeading method is missed each time
-(IBAction) NextHeading{
[audio stop];
NSString *Filename = [[NSString alloc]initWithFormat:#"CH%#S%#",Heading,Meaning];
Filepath = [[NSBundle mainBundle]pathForResource:Filename ofType:#"mp3"];
audio = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:Filepath] error:NULL];
audio.delegate = self;
[audio play];
[Filename autorelease];
}
-(IBAction) NextHeadingMeaning {
[audio stop];
NSString *Filename = [[NSString alloc] initWithFormat:#"CH%#S%#",bold**Chapter**bold, Meaning];
Filepath = [[NSBundle mainBundle]pathForResource:Filename ofType:#"mp3"];
audio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:Filepath] error:NULL];
audio.delegate = self;
[audio play];
[Filename autorelease];
}
Why is this happening and how can I resolve it ?
Please advice, thanks in advance.
You just used a single iVar (audio) as an player, and when you send NextHeading & NextHeadingMeaning message, the audio init with your sound_1.mp3 file firstly (it'll take some seconds if the mp3 file is big), then at the next moment (your first mp3 file might not inited, or has inited, but stopped followed by next message), you redo the init action with another mp3 file (sound_2.mp3), and finally, when the second mp3 file init done, audio plays sound_2.mp3. That's why you think the NextHeading is skipped.
So, to solve this problem, you can use a NSMutableArray iVar (e.g. audioPlayers), and create a local audio for both NextHeading & NextHeadingMeaning, and push it to audioPlayers.
And I think it is better to preload sound files if you can. :)
EDIT:
There's a playAtTime: method instead of play, you can delay the second audio player's playing time by this method, just like this:
[audioPlayer playAtTime:(audioPlayer.deviceCurrentTime + delay)];
delay is in seconds (NSTimeInterval).
There is no way that the first call is skipped, put a breakpoint in it or output something with NSLog() and you'll see. Most probable cause is that the first method doesn't do what you expect and this could be for various reasons - for example condition or specific timeout.
Edit:
After looking your code, it seems that you're missing some basic stuff like variable naming, variable scope and so. To simply make your code run, just replace the NSString *Filename.. string from the second method and probably it'll work. A better choice would be to visit Start Developing iOS Apps Today and follow the roadmap.

Audio and vibrate working in simulator not on ios device

First off, I'm fairly new with objective C. I want to play a sound and vibrate under a certain condition. My iPhone 4 is not on mute, I've checked case sensitivity and used both AVAudioPlay and SystemSound to try and play the file but even the vibrate will not work. AudioToobox and AVfoundation are imported in .h. The audio plays with both methods on the iOS simulator.
Heres the code using SystemSound:
if (al == 1){
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) #"Alarm", CFSTR ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);}
And with AVAudioPlayer:
if (al == 1) {NSString *path = [[NSBundle mainBundle] pathForResource:#"alarmtwo" ofType:#"wav"];
AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.numberOfLoops = 0;
theAudio.volume = 1.5;
[theAudio prepareToPlay];
[theAudio play];}
By the way, the variable al sets to 0 after it plays. Is my coding wrong to have the sound and vibrate work on the device itself? Is there a specific type of .wav file that needs to be played? Any help would be appreciated.
I was running into this same issue. There is actually a second volume setting specially for alerts that at least in my case was set to mute, even though my regular volume was up. Take a look under the sounds menu in the Settings app on the device and turn that up.
You probably don't want to use the alerts for an actual released app though if it is important that the sound actually play, since it will require users to make sure this separate audio setting is up.

xcode error: Parse Issue: Expected ';' after expression

I'm new to xcode and I'm trying to create a sound app. On line: theAudio.delegate = self; I'm receiving the error message:
error: Parse Issue: Expected ';' after expression
Below is a copy of the code.
- (IBAction)play:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:#"winning" ofType:#"mp3"];
if(theAudio)[theAudio release];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: path] error:NULL];
theAudio.delegate = self;
[theAudio play];
}
Any help would be much appreciated.
I was getting a similar build errors in CoreFoundation.framework.
CFURL.h: Expected ';' after top level declarator
CFFileSecurity.h: Expected function body after function declarator
CoreFoundation.h: 'CoreFoundation/CFUserNotification.h' file not found
To fix them, I deleted my project's derived data. I did this in Xcode under the Projects Organizer, in the Organizer Window, Window > Organizer (Command-Shift-2).
Other Things I Tried First That Failed
Clean (Command-Shift-K).
git clean -dXf (doesn't delete derived data by default), which for me (since I ignore xcuserdata), removes:
MyApp.xcodeproj/project.xcworkspace/xcuserdata/
MyApp.xcodeproj/xcuserdata/
Restart Xcode.
Restart OS X.
Reinstall Xcode.
I was about to reformat my harddrive and reinstall OS X, which now I see would've worked too. I'm glad I figured out a much faster, more direct way to fix this issue.
Release the audio after play.
[theAudio play];
[theAudio release];
or try this one
-(void) myPlay: (NSString *) soundFile ofType:(NSString *) ext{
if (ext == nil) {
ext = #"caf";
}
//SystemSoundID soundID;
//create and assign soundID to a particular sound
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:soundFile ofType:ext]] , &soundID);
//AudioServicesPlayAlertSound(soundID);
//To play the sound
AudioServicesPlaySystemSound (soundID);
//Function to allocate a function to be called after the sound(with SoundID) ends(optional)
AudioServicesAddSystemSoundCompletion (soundID,NULL,NULL,soundCompleted,
(void*) self);
}

maximize the sound effect in iPhone game by code?

I just built a game. It already has all the sounds. But for some reasons the sound effect of the click button is still small. How could I maximize the volume. I am not sure it is because of the quality of the sound files itself or because I din't increase the volume by code? could you guys help me out. Thanks in advance. Here is my code.
-(void) play
{
NSString *path = [NSString stringWithFormat:#"%#%#",[[NSBundle mainBundle] resourcePath],#"/menu_button_2.wav"];
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory :NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath ,&soundID);
AudioServicesPlaySystemSound(soundID);
//AudioServicesDisposeSystemSoundID (soundID);
}
From the System Sound Services Reference:
The interface does not provide level, positioning, or timing control
I would assume level implies volume.
If you use AVAudioPlayer you can set the volume from 0.0 to 1.0 with the volume property, but I am sure that opens up a new set of problem tradeoffs.