AudioStreamer works on iPhone (Device) but crash on simulator - ios

if (!streamer) {
NSURL *url =[NSURL URLWithString:#"http://y1.eoews.com/assets/ringtones/2012/5/18/34049/oiuxsvnbtxks7a0tg6xpdo66exdhi8h0bplp7twp.mp3"];
AudioStreamer *tempStreamer = [[AudioStreamer alloc] initWithURL:url];
self.streamer = tempStreamer;
[tempStreamer release];
}
[streamer start];
When it begin to play, it crash in simulator and xcode shows the erro is :libc++abi.dylib`__cxa_throw, but it runs well in device.in another demo, it runs well both in simulator and device.
I can not find the reason.

If you have enabled beakpoint for All exceptions, please disable it from Breakpoint Navigator. This should solve your problem.

Related

iOS 8.3 Share Extension - Launching URL Schemes

since iOS 8.3 update my share extension (which calls my main app using URL Schemes) stopped working. So I found out that the UIWebView approach I had to launch my app is not working anymore. I also tried the approach Apple recommends, using NSExtensionContext, and still no results. Any thoughts about this? My code follows:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
[self.view addSubview: webView];
NSString *urlString = "com.myappscheme://shareextension";
NSString * content = [NSString stringWithFormat : #"<head><meta http-equiv='refresh' content='0; URL=%#'></head>", urlString];
[webView loadHTMLString:content baseURL:nil];
and
[self.extensionContext openURL:[NSURL URLWithString:urlString] completionHandler:^(BOOL success)
{
NSLog(#"fun=%s after completion. success=%d", __func__, success);
}];
I try executing both blocks of code on the didSelectPost method from my SLComposeServiceViewController controller, which was where it worked fine previously, before updating my device to iOS 8.3
You can make a try with this code, this works but I don't know if would be accepted by Apple.
UIResponder* responder = self;
while ((responder = [responder nextResponder]) != nil) {
NSLog(#"responder = %#", responder);
if ([responder respondsToSelector:#selector(openURL:)] == YES) {
[responder performSelector:#selector(openURL:) withObject:[NSURL URLWithString:#""]];
}
}
extensionContext.openURL is meant only for Today extensions. Apple does not provide a public API to achieve this, and it seems in iOS 8.3, Apple has blocked some of the workarounds. This seems by design. If you believe this functionality is needed, please open an enhancement request / bug report.

Open URL scheme from iOS extension

I have this code that return success = NO
[self.extensionContext openURL:[NSURL URLWithString:#"URLApp://"] completionHandler:^(BOOL success) {
[self.extensionContext completeRequestReturningItems:nil completionHandler:nil];
}];
So and I can't open containing app from my share extension when I debug it.
I've configured main target of contained app like this:
I've tested open URLApp:// from safari and it works for me.
I also used some examples provided here to understand how to open containing app using url scheme.
EDIT: Ok, just a little correction here. I got it working with placing a button over the label just like suggested above and the following code:
NSURL *url = [NSURL URLWithString:#"floblog://"];
[self.extensionContext openURL:url completionHandler:nil];
I linked it to a "Touch Up Inside" event. However, this also causes the app to launch when the user scrolls the Today view.
=======================================
I ran into the same issue. However, it seems that there is no solution for now since the release notes for the first beta of iOS 8 mention:
Known Issues: openURL does not work from an extension.
So I guess we will at least have to wait until beta 2.
I found this answer here by Julio Bailon:
UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
NSString *urlString = #"URLApp://";
NSString * content = [NSString stringWithFormat : #"<head><meta http-equiv='refresh' content='0; URL=%#'></head>", urlString];
[webView loadHTMLString:content baseURL:nil];
[self.view addSubview:webView];
[webView performSelector:#selector(removeFromSuperview) withObject:nil afterDelay:2.0];

Simply Playing A Sound in iOS

I'm trying to play a sound when a button is clicked. First, I imported the AudioToolbox in the header file, then added the code into the IBAction that fires when the button is pressed, like so:
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)button1:(id)sender {
NSString *soundPath = [[NSBundle mainBundle] pathForResource:#"mySong" ofType:#"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:soundPath], &soundID);
AudioServicesPlaySystemSound (soundID);
}
I even threw an NSLog in the method to make sure it's firing. It is. I also but in a foo path in the string to see if it would crash, it did. I made sure that I dragged and dropped the short sound file into the app as well. Tested my speakers, tested audio on the device simulator by going to youtube on the simulator, everything. I can't figure out what I'm doing wrong.
When I changed the code to this:
- (IBAction)button1:(id)sender {
AVAudioPlayer *testAudioPlayer;
// *** Implementation... ***
// Load the audio data
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"3" ofType:#"wav"];
NSData *sampleData = [[NSData alloc] initWithContentsOfFile:soundFilePath];
NSError *audioError = nil;
// Set up the audio player
testAudioPlayer = [[AVAudioPlayer alloc] initWithData:sampleData error:&audioError];
if(audioError != nil) {
NSLog(#"An audio error occurred: \"%#\"", audioError);
}
else {
[testAudioPlayer setNumberOfLoops: -1];
[testAudioPlayer play];
}}
I get the error: WARNING: 137: Error '!dat' trying to set the (null) audio devices' sample rate
Hi as per you question can you please check whether you audio file is present in you project folder.It might happen that u have forgotten to checkmark "copy item if needed" so it might not be there in your project file.
You can also play sounds provided in device. Visit the below link it will be helpful.
https://github.com/TUNER88/iOSSystemSoundsLibrary
I've tested your code and it working fine and not getting crashed. Here's what I did.
As said in #matt's comment, sound playback fails in the Simulator. I had this problem when trying to play back a video.
The funny part is that sound plays just fine for the same video inside the Photos app.

Xcode Exception Breakpoint Always Pauses On Property

This has driven me nuts for a long time now. I am using Xcode 4.6 but this has been happening for several versions. When I turn on breakpoints and add the Exception Breakpoint, it always pauses on a line of code where I'm setting up an audio player. I set some up before and after the same way, but it only pauses on that one.
Here is the code I'm using:
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];
self.playedSongs = [NSMutableSet setWithCapacity:9];
[self loadSettingsFromFile];
NSURL *sfxPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"Snap.aiff" ofType:nil]];
self.snapSfx = [[[AVAudioPlayer alloc]initWithContentsOfURL:sfxPath error:nil]autorelease];
self.snapSfx.volume = 1.f;
NSURL *fireworksPath;
if ([OriginalIPadChecker isNotiPadOriginal]) {
fireworksPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"FireworksSFX.mp3" ofType:nil]];
}
else{
fireworksPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"NoFireworksSFX.mp3" ofType:nil]];
}
self.fireWorksSfx = [[[AVAudioPlayer alloc]initWithContentsOfURL:fireworksPath error:nil]autorelease];
self.fireWorksSfx.volume = 1.f;
NSURL *poofPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"Remove Poof.mp3" ofType:nil]];
//The line below is the one that it pauses on
self.removePoof = [[[AVAudioPlayer alloc]initWithContentsOfURL:poofPath error:nil]autorelease];
self.removePoof.volume = 1.f;
NSURL *newHighScorePath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"New High Score.mp3" ofType:nil]];
self.theNewHighScore = [[[AVAudioPlayer alloc]initWithContentsOfURL:newHighScorePath error:nil]autorelease];
self.theNewHighScore.volume = 1.f;
NSURL *badgeInTrophyPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"Badge In Trophy.aiff" ofType:nil]];
self.badgeInTrophy = [[[AVAudioPlayer alloc]initWithContentsOfURL:badgeInTrophyPath error:nil]autorelease];
self.badgeInTrophy.volume = 1.f;
NSURL *dingPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"Ding.aif" ofType:nil]];
self.ding = [[[AVAudioPlayer alloc]initWithContentsOfURL:dingPath error:nil]autorelease];
self.ding.volume = 1.f;
The app doesn't crash and the sound plays fine, but the debugger always pauses on that one lineā€”even if I move it somewhere else, it still pauses. I can continue the execution and it works just fine, but this really bugs me.
I don't get why it pauses. Any ideas?
As explained in the comment of Xcode stops on prepareToPlay, the reason for the breakpoint is that you were setting a generic breakpoint of type 'exception on All' which responds to a signal which is fired by the c++ library. It is better to use an "Objective-c" exception breakpoint, which will protect for such cases.
Try this and update the question on where it stops (if it stops):
AVAudioPlayer *foo;
NSError *error = nil;
assert(poofPath);
foo = [AVAudioPlayer alloc];
foo = [foo initWithContentsOfURL:poofPath error:&error];
assert(foo);
[self setRemovePoof:foo];
[foo release];
If the assert kicks in, that's probably an Apple issue. Unfortunately there are cases of Apple internal frameworks using try/catch, and they will trigger the breakpoint. Its not common but does happen.
If in the end that foo is not nil and the error is also nil, the best you can do is enter a bug report at bugreporter.apple.com (which would be great). Also, did you look at poofPath - is there any chance that the URL returns anything other than pristine audio?
My guess is that Apple tries to open and process the file, its gets an internal exception because there is something "odd" or abnormal about the file. Then the framework does additional work, and manages to read the file. So you get your sound but the exception too. Take some common type of mp3 and put that in your app bundle, and try to open it. See if it (and maybe a few other files) gives the same error. Or create a demo project with the sound and upload it (in the end you may need to submit the demo project to Apple in a bug report). These kinds of things should be bug reported.
EDIT: Unfortunately there are cases of Apple internal frameworks using try/catch, and they will trigger the breakpoint. Then, as mentioned earlier, some later code finally figures out how to decode the file and does.
The original poster has responded in a comment that this particular file was created with Audacity, and has heard that such files often have decode issues.

Xcode 4.5 causing errors in iOS 5 apps

I having working on a timer application since last 3 to 4 months (when there was no sign of iOS 6) but due to some issues could not complete it. Now since the advent of iOS 6.. I am getting error in my code. I recently downloaded the xcode 4.5 and iOS 6 SDK (within it). Now when I run the app. It crashes on different occasions. Sometimes crashes right when it is started. Some times no crashes at all.
Sometimes give me SGBRT error. Sometimes Bad_exc error(memory error). I don't know how to handle this. I have downloaded the iOS 5.1 simulator and on that when i run the app. No crashes at all but when I run the app on iOS 6 simulator. Wham! it crashes right away.
I am in dire need of guidance. Anyone who has experienced the same error and got it troubleshoot please help me too.
Thanks in Advance
Fahad.
- P.S. I added breakpoints to detect the errors and I was able to catch only one but could not understand why I got this error. Here is the code:
-(void) playAppSound:(NSString *) fName withExt:(NSString *) ext{
NSString *path = [[NSBundle mainBundle] pathForResource : fName ofType :ext];
if ([[NSFileManager defaultManager] fileExistsAtPath : path])
{
NSURL *pathURL = [[NSBundle mainBundle] URLForResource:fName withExtension:ext];
// Instantiates the AVAudioPlayer object, initializing it with the sound
if(self.appSoundPlayer)
{
if([self.appSoundPlayer isPlaying])
{
[self.appSoundPlayer stop];
[self.appSoundPlayer release];
}
}
//Thread breaks down in the next line self. appSoundPlayer...
self.appSoundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: pathURL error: nil] ;
//self.appSoundPlayer.numberOfLoops = 1;
[appSoundPlayer setDelegate:self];
[appSoundPlayer prepareToPlay];
//[appSoundPlayer setVolume:1.0];
[appSoundPlayer play];
}
else{
// NSLog(#"error, file not found: %#", path);
}
}
Check Framework versions (SDK 5 <- wrong, SDK6 <-right)

Resources