ios - Xcode 6.0.1 新警告

标签 ios objective-c xcode6 mpnowplayinginfocenter

在更新到最新版本的 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;
}

最佳答案

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

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

关于ios - Xcode 6.0.1 新警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26220537/

相关文章:

ios - 如何使用 NSNumberFormatter 将数字格式化为有限字符的 NSString?

ios - 如何在源代码管理下获取 Images.xcassets?

iphone - 尝试在 ios 中使用 TableView ,出现错误

iphone - 使用 MKCoordinateRegion 将 MKMapView 聚焦在 NSString 经纬度坐标上

ios - Xcode 6 中的默认设备方向

ios - 有什么办法可以改善 iOS 当前位置?

objective-c - 如何在 CocoaLibSpotify 注销时清除用户名和密码?

ios - 如何从 iOS 中的一组 url 预加载图像?

ios - 没有自动布局的设计,因此它适用于各种尺寸的设备

objective-c - 在 iOS 8/Xcode 6 GM Seed 上使用自动布局调整大小时 UIScrollView 中断