Objective C - 如何访问 NSNotification 内部对象?
我想从通知访问内部对象。我需要获取关键的 AVSystemController_AudioVolumeChangeReasonNotificationParameter。
如果我调用 [sender object] 我会得到这个输出。但如果我打电话,
[[sender object] userInfo]
我只会得到“无法识别的选择器发送到实例”。这是为什么?
NSLog(@"%@", [sender object]) 输出:
NSConcreteNotification 0x157a30 {name = AVSystemController_SystemVolumeDidChangeNotification; object = AVSystemController: 0x1616c0; userInfo = { "AVSystemController_AudioCategoryNotificationParameter" = "Audio/Video"; "AVSystemController_AudioVolumeChangeReasonNotificationParameter" = ExplicitVolumeChange; "AVSystemController_AudioVolumeNotificationParameter" = 1; }}
如果无法访问 userInfo,我可以获取 NSLog 的输出来进行字符串搜索吗?
I want to access a inner object from a notification. I need to get the key AVSystemController_AudioVolumeChangeReasonNotificationParameter.
If I call [sender object] I get this output. But if I call
[[sender object] userInfo]
I only get "unrecognized selector sent to instance". Why is that?
NSLog(@"%@", [sender object]) output:
NSConcreteNotification 0x157a30 {name = AVSystemController_SystemVolumeDidChangeNotification; object = AVSystemController: 0x1616c0; userInfo = { "AVSystemController_AudioCategoryNotificationParameter" = "Audio/Video"; "AVSystemController_AudioVolumeChangeReasonNotificationParameter" = ExplicitVolumeChange; "AVSystemController_AudioVolumeNotificationParameter" = 1; }}
If it is not possible to access userInfo, can I get the output of NSLog to do a string search?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
的输出
NSLog 的输出实际上看起来像Are you certain you were Calling [sender object]?
对象通常是发布通知的对象。在您的情况下,很可能是具有 AVSystemController 类的对象 用户
信息可以通过访问
所以请尝试
顺便说一句:如果您尝试将音量按钮的功能映射到其他功能(例如“拍照”-操作),您的应用程序将获胜不被批准。万一。
Your output from NSLog actually looks like the output of
Are you sure you were calling [sender object]?
object is often the Object that posted the notification. In your case most likely an object with class AVSystemController
The userinfo can be accessed with
So please try
BTW: If you try to map the function of the volume-buttons to some other function (for example "Take Photo"-Action) your app won't be approved. Just in case.