my code is crashing because of this problem:
if ([recorder peakPowerForChannel:0]==0 )
{
NSLog(@"we are recording now because signal is at high volume... ");
if(flag==1)
{
start = [NSDate date];
}
[recorder stop];
}
else
{
[recorder stop];
stop = [NSDate date];
duration = [start timeIntervalSinceDate:stop];
stop and start are NSDate and declared at the start of the .m
,The problem is that because “duration” and “start” are not in the same “if”, and moving “start” to be under the “else” solve it. but i need it to be there.
why is that happen? the software is going for sure to the “start” before she goes to the stop, so does he forget the start?
The
[NSDate date]gives a autoreleased object to the caller.Change
start = [NSDate date];tostart = [[NSDate date] retain];and you should be fine.Then you have to balance the retain counts in the end.