【问题标题】:Xcode 6.0.1 new warningXcode 6.0.1 新警告
【发布时间】:2014-10-06 16:22:57
【问题描述】:

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

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

代码:

- (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;
}

【问题讨论】:

  • 听起来 XCode 6 中的某些类型推断被破坏了。演员将解决这个问题。

标签: ios objective-c xcode6 mpnowplayinginfocenter


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-11
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多