gpt4 book ai didi

ios - 收到的事件子类型是无法识别的选择器

转载 作者:行者123 更新时间:2023-11-29 02:00:24 25 4
gpt4 key购买 nike

我试图检测是否在控制中心按下了后退或前进滑动按钮,但是当我运行以下代码时,它会崩溃 if (receivedEvent.subtype == UIEventSubtypeRemoteControlNextTrack无法识别的选择器发送到实例 0x170259890。我不确定哪里出了问题以及为什么它不起作用。

- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNowPlayingItemChanged:) name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification object:self.player];
[self.player beginGeneratingPlaybackNotifications];
}

-(void)handleNowPlayingItemChanged :(UIEvent *)receivedEvent {
NSLog(@"worked");
if (receivedEvent.subtype == UIEventSubtypeRemoteControlNextTrack) {
NSLog(@"next track");
}
}

最佳答案

任何时候你使用 NSNotificationCenter 设置一个通知处理程序,你必须知道你提供的方法必须以特定的方式设置。来自 addObserver:selector:name::

的文档

Selector that specifies the message the receiver sends notificationObserver to notify it of the notification posting. The method specified by notificationSelector must have one and only one argument (an instance of NSNotification).

这意味着您的 handlePlayingItemChanged: 方法必须是:

- (void)handleNowPlayingItemChanged:(NSNotification *)notification {
NSLog(@"worked");

MPMusicPlayerController *player = notification.object;
// get the nowPlayingItem or any other property as needed
}

关于ios - 收到的事件子类型是无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30449662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com