也许在升级到Xcode 10.1之后,当我的AVAudioplayer应该播放MP3时,我的应用在启动时崩溃。我看不到如何调试它。
我已经尝试了各种方法来理解该问题,包括在初始化时显示潜在的错误。
//AppDelegate.h
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#include <AudioToolbox/AudioToolbox.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate> {
AVAudioPlayer *myAudioPlayer; }
@property (strong, nonatomic) UIWindow *window; @property (nonatomic, retain) AVAudioPlayer *myAudioPlayer; @property (assign,nonatomic) NSUInteger bSound; @property (assign,nonatomic) double fVolume;
@end
//AppDelegate.m
#import "AppDelegate.h"
#import <AVFoundation/AVFoundation.h>
#include <AudioToolbox/AudioToolbox.h>
@implementation AppDelegate
@synthesize myAudioPlayer;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"theBoxCatGames-09eCommerce" ofType: @"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath ];
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:YES error:nil];//checked, there is no error
myAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil]; //checked, there is no error
[myAudioPlayer play]; //<--------raised exception
return YES;
}
我得到一个libc ++ abi.dylib`__cxa_throw:_Unwind_RaiseException
<AVAudioPlayer: 0x60000365f220>
<AudioPlayerImpl: 0x600001255080>
self->myAudioPlayer->_impl->_delegate:
<nil>
self->myAudioPlayer->_impl->_audioSession:
<AVAudioSession: 0x600003450a00>
我不确定在异常使程序停止时应在对象浏览器中找到哪些值。
(我还显示了其他值,例如设备)
self->myAudioPlayer->_currentDevice: <nil>