我正在使用我的 AppDelegate
来处理一些音频文件。我已将其设为 AVAudioPlayer
委托(delegate),以便我可以使用 audioPlayerDidFinishPlaying
等方法。
我是这样做的:
@interface AppDelegate : UIResponder <UIApplicationDelegate, AVAudioPlayerDelegate>
然后在任何 ViewController
中,我通过以下方式访问我的 AppDelegate
:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
一切正常,但我收到以下警告:
Assigning to 'APPDelegate *__strong' from incompatible type 'id<UIApplicationDelegate>'
最佳答案
您需要将其转换为您的 AppDelegate
类型 -
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
关于ios - 使用 AppDelegate 作为单例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22745326/