作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一个 iPhone 音乐应用程序来处理音乐播放和暂停并维护自己的播放列表。我正在尝试使播放/暂停 Remote 功能(在耳塞和上滑屏幕上)适用于我的应用程序中的音乐播放。
下面是我在音乐播放器相关的初始化方法中放的代码(它是MPMusicPlayerController的一个实例,通过调试确定这 block 代码被调用了),我后面会讲我遇到的问题代码:
[self.musicController beginGeneratingPlaybackNotifications];
// listen to remote control events
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
if ([self canBecomeFirstResponder]) {
NSLog(@"Can be first responder");
[self becomeFirstResponder];
NSLog([NSString stringWithFormat: @"is first responder now? %@", [self isFirstResponder] ? @"yes" : @"no"]);
} else {
NSLog(@"Cannot be first responder");
}
MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
[commandCenter.togglePlayPauseCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) {
NSLog(@"TK: toggle command");
return nil;
}];
[commandCenter.playCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) {
NSLog(@"TK: play command");
return nil;
}];
[commandCenter.pauseCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) {
NSLog(@"TK: pause command");
return nil;
}];
最佳答案
您应该启用 View ( View Controller )成为第一响应者- (BOOL)canBecomeFirstResponder {
return true;
}
关于ios - MPRemoteCommandCenter 事件处理程序从未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30340102/
背景 我最近在 merge 期间遇到了一个意外未 merge 的文档文件的问题。 无论出于何种原因,我搞砸了 merge 并有效地删除了文件(和其他几个文件),因为我忘记了它们的存在。 现在我想查看我
我在我的网站上使用旧的 mysql 版本和 php 版本 4。 我的表结构: | orders_status_history_id | orders_id | orders_status_id |
我是一名优秀的程序员,十分优秀!