【发布时间】:2017-12-28 01:30:08
【问题描述】:
我是 iOS 新手,我正在尝试使用 Objective-c 构建一个应用程序。我遇到的问题是屏幕锁定时无法显示音频控件。
我正在使用 AVPlayer 播放音频。
在 viewDidLoad 中我调用了这个方法
- (void)screenLocked{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
}
那个方法调用这个
- (void)appDidEnterBackground:(NSNotification *)notification {
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter
sharedCommandCenter];
[[remoteCommandCenter playCommand] addTarget:self
action:@selector(test)];
[[remoteCommandCenter skipForwardCommand] addTarget:self
action:@selector(test)];
[[remoteCommandCenter skipBackwardCommand] addTarget:self
action:@selector(test)];
[[remoteCommandCenter togglePlayPauseCommand] addTarget:self
action:@selector(test)];
[[remoteCommandCenter pauseCommand] addTarget:self
action:@selector(test)];
}
- (void)test{
NSLog(@"Logging");
}
当我在模拟器中运行应用程序并将屏幕锁定到我沮丧时,没有出现任何控件。任何帮助,将不胜感激。
【问题讨论】:
标签: ios objective-c xcode ios-simulator