How can I make the Control Center slider editable?

后端 未结 6 880
栀梦
栀梦 2021-01-04 20:54

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

6条回答
  •  伪装坚强ぢ
    2021-01-04 21:08

    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 :-)

提交回复
热议问题