I\'m working on an app that will play sound files. If I open apple music app, the slider let me moving between the song where I am.
Other apps like spotify
In addition to implementing the callback, it seems that you would have to set the canBeControlledByScrubbing
property to true. Unfortunately, there is no public accessor to set it, so you would have to do it as follows (and won't be able to submit your app to the AppStore):
NSNumber *shouldScrub = [NSNumber numberWithBool:YES];
[[[MPRemoteCommandCenter sharedCommandCenter] changePlaybackPositionCommand]
performSelector:@selector(setCanBeControlledByScrubbing:) withObject:shouldScrub];
[[[MPRemoteCommandCenter sharedCommandCenter] changePlaybackPositionCommand]
addTarget:self
action:@selector(handleChangePlaybackPositionCommand:)];
If you do it like this, you will get the callback on your handleChangePlaybackPositionCommand:
method, taking an MPChangePlaybackPositionCommandEvent
as its only parameter.
If you do want to support older versions of iOS than 9.1, I'd suggest to check for the iOS version before executing the above code to prevent crashes (You can either do it using the new API introduced with iOS 8, or if you want to support iOS 7 and earlier as well, using something like
[[[UIDevice currentDevice] systemVersion] compare:@"9.1" options:NSNumericSearch] != NSOrderedAscending
I hope this helps :-)