Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update MPNowPlayingInfoCenter in Swift?

In objective c, I've been using code like this to update MPNowPlayingInfoCenter:

[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo: 
    @{ MPMediaItemPropertyArtist : @"Artist!",
        MPMediaItemPropertyTitle : @"Title! }];

But in Swift, it doesn't seem like the function "setNowPlayingInfo" is recognized:

MPNowPlayingInfoCenter.defaultCenter()....  // Can't identify 'setNowPlayingInfo()'

Is there anything I'm missing?

like image 735
jmkr Avatar asked Jun 17 '14 18:06

jmkr


1 Answers

In Swift, getters/setters work differently. Since there are no more properties like in ObjC, there are no automatically generated setters/getters for you. You should just access the variable directly.

In your case, use:

MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = [MPMediaItemPropertyArtist : "Artist!",  MPMediaItemPropertyTitle : "Title!"]
like image 133
Jack Avatar answered Sep 20 '22 23:09

Jack