Hardware Volume buttons change in app volume

心已入冬 提交于 2019-12-04 19:53:58

By default the hardware buttons will change the alarm volume unless you have an open audio session when they use the buttons. I would recommend opening an AVAudioSession to have them change it or placing a volume slider somewhere in your app to have them change the volume.

This is a difficult problem to solve perfectly because users aren't told what is wrong and many times don't look to see that the ringer volume is what is being changed.

Use MPVolumeView!

If you add an MPVolumeView to your UIWindow (you can make it hidden), the MPVolumeView will automatically take over the hardware buttons for you. The hardware buttons will now affect your app's volume levels instead of the system's.

MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectZero];
volumeView.showsRouteButton = NO;
volumeView.hidden = YES;
[self.window addSubview:volumeView];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!