2010-01-12 25 views
1

我在工程学校学到的一件事情是始终对输入进行强烈验证。我认为使用iPhone SDK可以创建声音和震动选项是非常棒的。我想把这两个都放到我的Alert View中,它显示了用户没有正确填写字段的时间。试图将振动和声音添加到我的警报视图

但是,我收到了很多错误。无法将振动和声音选项置于警报视图中吗?这里是我用下面我把所有上面的代码中

- (void)textFieldDidEndEditing:(UITextField *)textField 

方法的代码,

 //create vibrate 
     AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); 

     //play sound 
    SystemSoundID pmph; 
    id sndpath = [[NSBundle mainBundle] 
        pathForResource:@"mySound" 
        ofType:@"wav" 
        inDirectory:@"/"]; 
    CFURLRef baseURL = (CFURLRef) [[NSURL alloc] initFileURLWithPath:sndpath]; 
    AudioServicesCreateSystemSoundID (baseURL, &pmph); 
    AudioServicesPlaySystemSound(pmph); 
    [baseURL release]; 

     //show alert view 
    UIAlertView *alert = [[UIAlertView alloc] 
          initWithTitle:@"Age Error" 
          message:@"Your age must be at least 40 years old and less than 100 years old" 
          delegate:nil 
          cancelButtonTitle:@"OK" 
          otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 

这是我得到的错误,当我尝试运行它 http://screencast.com/t/Nzc5NDdhMmI

任何帮助将不胜感激。不知道我做错了什么,因为我直接从其他来源在线粘贴此代码。

回答

4

我从来没有使用声音服务,但它看起来像你需要导入AudioToolbox框架。

#import <AudioToolbox/AudioToolbox.h> 
+0

啊是的,你是绝对正确的。我没有包含AudioToolbox框架。但是,现在我正在使用正确的代码和框架,但它只是停止并且不会产生我的声音。这是一个视频(http://screencast.com/t/ZmM3MGRm),这里是控制台错误(http://screencast.com/t/YzFjNzE4)的镜头。 – HollerTrain 2010-01-12 14:57:49

+0

嘿修好了。 1.本来没有导入框架,2.文件本身搞砸了。感谢coneybeare在那一个! – HollerTrain 2010-01-12 16:55:51