无法播放没有错误的声音

时间:2013-02-10 13:39:00

标签: iphone ios audio

我一直在努力寻找这个问题的解决方案。我已正确设置带有声音文件的AudioToolbox框架,没有任何错误。它编译并运行正常,但当我尝试按下按钮播放声音时,我在一个名为main.m的文件中看到一个丑陋的绿色突出显示。 以下是尝试播放声音后我带来的main.m文件:

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char *argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

return UIApplicationMain行,绿色显示的位置。它说Thread 1: Signal SIGABRT

这里有什么问题?

以下是我的ViewController .m和.h文件:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize bannerIsVisible;


-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
if (!self.bannerIsVisible) {

    [UIView beginAnimations:@"animateAdBanner" context:NULL];
    banner.frame = CGRectOffset(banner.frame, 0, -50.0f);
    [UIView commitAnimations];
    self.bannerIsVisible = YES;
}
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
if (self.bannerIsVisible) {
    [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
    banner.frame = CGRectOffset(banner.frame, 0, 50.0f);
    [UIView commitAnimations];
    self.bannerIsVisible = NO;
 }
}

- (void)viewDidLoad
{
[super viewDidLoad];

adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, 460.0f);
adView.requiredContentSizeIdentifiers = [NSSet       setWithObject:ADBannerContentSizeIdentifierPortrait];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:adView];
adView.delegate=self;
self.bannerIsVisible=NO;

}

- (void)didReceiveMemoryWarning


{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)cstring:(id)sender {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"CString", CFSTR    ("caf"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
@end

现在我的.h:

#import <iAd/iAd.h>
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import <iAd/ADBannerView_Deprecated.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

@interface ViewController : UIViewController <ADBannerViewDelegate> {


ADBannerView *adView;
BOOL bannerIsVisible;

}

@property (nonatomic, assign) BOOL bannerIsVisible;


- (IBAction)cstring:(id)sender;












@end

1 个答案:

答案 0 :(得分:0)

您需要弄清楚错误的来源。您可以单步执行,也可以至少执行以下两个步骤之一:

  1. 在主服务器中安装this patch,以记录控制台的例外情况。
  2. 在Xcode断点选项卡的底部,按“+”添加新断点,然后选择添加例外断点的选项。 (我忘记了显示的确切单词,但这很明显。)这会在发生异常时导致断点。