Xcode 6.0.1新警告

时间:2014-10-06 16:22:58

标签: ios objective-c xcode6 mpnowplayinginfocenter

在我更新到最新版本的Xcode之前,我没有收到此错误警告?

Incompatible pointer types initializing 'MPNowPlayingInfoCenter' with an expression of type 'NSNotificationCenter’

CODE:

- (void)doUpdateNowPlayingCenter 
{
    if (!self.updateNowPlayingCenter || !self.nowPlayingItem)
    {
        return;
    }

    Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

    if (!playingInfoCenter)
    {
        return;
    }

    MPNowPlayingInfoCenter *center = [playingInfoCenter defaultCenter];
    NSDictionary *songInfo = @
    {
         MPMediaItemPropertyTitle: [self.nowPlayingItem valueForProperty:MPMediaItemPropertyTitle],
         MPMediaItemPropertyPlaybackDuration: [self.nowPlayingItem valueForProperty:MPMediaItemPropertyPlaybackDuration]
    };

    center.nowPlayingInfo = songInfo;
}

2 个答案:

答案 0 :(得分:1)

您可以通过以这种方式投射默认中心来静音警告:

MPNowPlayingInfoCenter *center = (MPNowPlayingInfoCenter*)[playingInfoCenter defaultCenter];

答案 1 :(得分:0)

最后一个版本是6.1 更新到最新版本。