问题描述
我的应用程序使用 iPodMusicPlayer,当暂停时,用户可能会外出并在 Apple 的音乐应用程序中进行更改,例如创建或修改播放列表,然后返回到我的应用程序.
My app uses the iPodMusicPlayer and, when suspended, the user might go out and make changes in Apple's Music App, for example creating or modifying a Playlist, then return to my App.
我收到了预期的 MPMediaLibraryDidChangeNotification,这很好,我会更新我的参考资料等,但我在大约 2 分钟后收到第二个 MPMediaLibraryDidChangeNotification,我真的不需要.
I receive the expected MPMediaLibraryDidChangeNotification, which is fine and I deal with it updating my references etc., but I receive a second MPMediaLibraryDidChangeNotification about 2 minutes later which I really don't need.
关于避免第二次通知有什么想法吗?
Any ideas on avoiding this second notification?
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notification_iPodLibraryDidChange:) name: MPMediaLibraryDidChangeNotification object:nil];
[[MPMediaLibrary defaultMediaLibrary] beginGeneratingLibraryChangeNotifications];
推荐答案
if( !self.lastModifiedDate ) self.lastModifiedDate = [[NSDate alloc] init];
if( [self.lastModifiedDate compare:[[MPMediaLibrary defaultMediaLibrary] lastModifiedDate]] == NSOrderedSame ) return;
self.lastModifiedDate = [[MPMediaLibrary defaultMediaLibrary] lastModifiedDate];
我的通知处理程序方法中的以上几行处理了额外的调用.仍然不知道为什么我会得到它.
The above lines in my notification handler method deal with the extra call. Still no idea why I'm getting it.
这篇关于MPMediaLibraryDidChangeNotification 调用了两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!