我一直在努力寻找这个问题的解决方案。我已正确设置带有声音文件的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
答案 0 :(得分:0)
您需要弄清楚错误的来源。您可以单步执行,也可以至少执行以下两个步骤之一: