switch控件 - ios switch 是否震动 是否系统声音和是否接收新消息
怪我咯
怪我咯 2017-04-17 14:23:01
0
1
713

第一次开发关于“调用iPhone的系统声音和震动,是否接收新消息”,首次用switch控件,在网上查了一些资料,但是还是一头雾水,我的代码和需求如下

导入框架:#import  - (void)viewDidLoad { [super viewDidLoad]; [self.shake addTarget:self action:@selector(ChangeShake:) forControlEvents:UIControlEventValueChanged]; [self.sound addTarget:self action:@selector(changeSound:) forControlEvents:UIControlEventValueChanged]; // Do any additional setup after loading the view from its nib. } -(void)ChangeShake:(UISwitch *)sender{ if (self.shake.isOn) { NSLog(@"开启状态————震动"); AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//系统声音 // AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);//警告声音 }else{ NSLog(@"关闭状态————震动"); } } -(void)changeSound:(UISwitch *)sender{ if (self.sound.isOn) { //播放声音 NSString *path = [[NSBundle mainBundle] pathForResource:@"message" ofType:@"wav"]; //音效文件路径 SystemSoundID soundID;//组装并播放音效 NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID); AudioServicesPlaySystemSound(soundID); AudioServicesDisposeSystemSoundID(soundID);//声音停止 NSLog(@"开启状态————声音"); }else{ NSLog(@"关闭状态————声音"); } }

以上这就是我的代码!
项目需求就像微信和QQ的设置那种效果!!!!!

求大神告知!!!!!!

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all (1)
黄舟

贴一段我用switch的代码。

- (void)viewDidLoad { [self.testswitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged]; } - (void)switchAction:(id)sender { UISwitch *switchButton = (UISwitch*)sender; BOOL isButtonOn = [switchButton isOn]; if (isButtonOn) { status = 0; } else { status = 1; } }

希望对你有帮助

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!