【问题标题】:Vibrations and alert not working in iOS振动和警报在 iOS 中不起作用
【发布时间】:2016-01-08 04:05:30
【问题描述】:

所以我在我的 iPad Mini 上运行,我的代码看起来像

-(void)viewDidLoad{
[super viewDidLoad]
AudioServicesPlaySystemSound(1005);
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate); 
}

我导入了

#import <AudioToolbox/AudioToolbox.h>
#import <AudioToolbox/AudioServices.h>

在我的 ViewController.h 中。只有第一个声音播放,即使根据文档,第二个声音也应该发出哔哔声。我该如何解决这个问题?

编辑: 对于看到这个的人,我认为在旧设备中这会发出哔哔声 - 文档说:

“根据特定的iOS设备,此函数会播放短促的声音并可能会触发振动。在各种iOS设备上调用此函数会执行以下操作:

iPhone—播放指定的声音。如果用户已将设置应用程序配置为响铃振动,也会调用振动。但是,如果您的应用程序的音频会话配置了 AVAudioSessionCategoryPlayAndRecord 或 AVAudioSessionCategoryRecord 音频会话类别,则设备不会振动。这样可以确保振动不会干扰录音。有关音频会话类别的说明,请参阅 Category Express Audio Roles。

iPod touch,原版 - 播放简短的提示旋律。

iPod touch,第 2 代和更新版本——播放指定的声音。”

但我认为该功能已被删除。

【问题讨论】:

  • 我做到了,但它仍然无法正常工作。我的 iPad mini 没有振动按钮,但根据文档 (kSystemSoundID_Vibrate) 应该在不振动的设备上发出蜂鸣声。

标签: ios objective-c audiotoolbox vibration


【解决方案1】:

iPad 上没有振动。 来自文档:

@constant       kSystemSoundID_Vibrate
Use this constant with the play sound APIs to vibrate the device
                    - iOS only 
                    - on a device with no vibration capability (like iPod Touch) 
                       this will do nothing

所以AudioServicesPlayAlertSound(kSystemSoundID_Vibrate); 在 iPad 上什么都不做

【讨论】:

    【解决方案2】:

    iPad 不支持物理振动。

    您只能在 iPhone 和更新版本的 iPod 中使用这些代码。

    【讨论】:

      猜你喜欢
      • 2020-12-28
      • 1970-01-01
      • 2019-06-29
      • 2012-06-29
      • 1970-01-01
      • 2016-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多