如何使用物镜将iPhone设为静音模式 [英] How Make iPhone to silent mode on/off using objective c

查看:139
本文介绍了如何使用物镜将iPhone设为静音模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个想要检测iphone是否处于静音模式的应用程序.

I am creating one app in which i want to detect that iphone is on silent mode or not.

我已经想到了下面的链接

I have already gone thought the below link

检测iPhone的铃声/静音/使用AVAudioPlayer的静音开关不起作用?

在iPhone上的静音模式和响铃模式之间切换

许多人说这违反了iPhone政策.但我已经看到许多应用程序也提供了此功能

many people says that it is against the iPhone policy. but i have seen many app which is also giving this functionality

检查下面的应用程序链接

check the below app link

https://itunes.apple.com/us/app/silentalert/id506092189?mt = 8

我还想更改iPhone的静音模式,就像上面的应用程序一样.

I also want to change the silent mode of the iPhone same as the above app is doing.

有人知道吗?

推荐答案

有办法,但是您的应用程序将被Apple拒绝(我不确定,也许不是).将MPVolumeView添加到视图中,但不向用户显示(为此,您可以根据视图更改框架).您可以从此控件获取声音级别.这是代码(已测试iOS +7):

There is way but your application will be rejected by Apple (I am not sure, may be not). Add a MPVolumeView to your view, but do not show it to the user (for this purpose you can change the frame according to your view). You can get the sound level from this control. Here is the code (iOS +7 is tested):


    - (void)someMethod
    {
        MPVolumeView *systemVolumeSlider = [[MPVolumeView alloc] initWithFrame:  CGRectMake(-100, -100, 16, 16)];
        [systemVolumeSlider setUserInteractionEnabled:NO];
        systemVolumeSlider.showsRouteButton = NO;
        [self.view addSubview: systemVolumeSlider];
        [systemVolumeSlider sendSubviewToBack:self.view];

        [[AVAudioSession sharedInstance] setActive:YES error:NULL];

        float currentSoundLevel = [self getVolumeLevel];
        NSLog(@"volume level : %f", currentSoundLevel); // if it is 0, the phone is in silent mode

        // do your job here... 

        [[MPMusicPlayerController applicationMusicPlayer] setVolume:1.0]; // 1.0 is the max level

        // do your job here...
     }

    - (float)getVolumeLevel
    {
        MPVolumeView *slide = [MPVolumeView new];
        UISlider *volumeViewSlider;
        for (UIView *view in [slide subviews]){
            if ([[[view class] description] isEqualToString:@"MPVolumeSlider"])
                volumeViewSlider = (UISlider *) view;
        }
        return [volumeViewSlider value];
    }

这篇关于如何使用物镜将iPhone设为静音模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆