本文介绍了NSUserDefaults关闭声音效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的应用上关闭音效

i try to off a sound effect on my app

播放方法为'[myMusic播放];

play method is ' [myMusic play];

-(void)viewDidLoad {
     BOOL soundIsOff = [defaults boolForKey:@"sound_off"];
     //the problem is here 
     //xcode compiler doesn't copile this code 
     [myMusic play] = soundIsOff;

}

声音代码:'///声音效果

sound code : ' ///sound effect

 NSString * musicSonati = [[NSBundle mainBundle] pathForResource:@"sound"      ofType:@"wav"];
 myMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL     fileURLWithPath:musicSonati] error:NULL];
 myMusic.delegate = self;
 myMusic.numberOfLoops = 0;

摇晃API代码:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {

 if (event.subtype == UIEventSubtypeMotionShake)

  //Play sound :
  [myMusic play] ; 
 }
}

推荐答案

看起来像您正在尝试为方法调用分配值.这就是为什么出现编译器错误的原因:

Looks like you are trying to assign a value to a method call. That is why you are getting the compiler error:

[myMusic play] = soundIsOff//这不起作用.

您可能想要这样的东西:

You probably want something like this:

if(!soundIsOff) {
    [myMusic play];
}

但是问题尚不清楚,所以这是一个猜测.

The question is unclear however, so this is a guess at this point.

这篇关于NSUserDefaults关闭声音效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 03:25