【问题标题】:How to check vibration state is On or Off by pogramatically in iphone? [duplicate]如何通过在 iphone 中以编程方式检查振动状态是打开还是关闭? [复制]
【发布时间】:2017-10-03 14:39:39
【问题描述】:

如何通过应用程序以编程方式检查系统振动是打开还是关闭? 在我的情况下,UI 设计就像 - 我在 viewcontroller 中设置了一个按钮。哪个功能是,当我按下按钮时,它会提醒我系统振动是打开还是关闭。这是下面的代码。但它不起作用。它总是与其他部分一起使用。

- (IBAction)checkVibrate:(id)sender {
 CFStringRef state;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);

if(CFStringGetLength(state) == 0)
{
    //off
    [self Alert:@"It seems that your phone's vibration is off. Please go to your phone setting and make the vibration ON"];
}
else
{
    //on
    [self Alert:@"It seems that your phone's vibration is On.If you want to off the vibration, please go to device setting and make vibration Off"];
}

}

如果我走错了路,请帮我解决这个问题?

【问题讨论】:

  • @user3182143 ,我知道这是一个重复的问题。但我正在尝试通过 [stackoverflow.com/questions/5519807/….那个时候我没有得到准确的输出。所以请帮帮我
  • 我在下面添加了所有来源。

标签: ios objective-c xcode8


【解决方案1】:

不,你不能。 Apple 没有提供 API 来访问它。

【讨论】:

  • 我的意思是,我只想检查振动模式(开或关),不希望改变振动模式。
【解决方案2】:

看到您的问题后,我试图找到解决方案。我在堆栈溢出和其他站点中准备了大部分其他答案。都告诉使用AVAudioSession

音频会话充当您的应用和 操作系统——反过来,底层的音频硬件。你用 它将您的应用程序的性质传达给操作系统 没有详细说明特定行为或所需交互的音频 与音频硬件。这将管理那些 音频会话的详细信息,以确保操作系统 可以最好地管理用户的音频体验。

更好的来源是

How to detect whether iPhone is vibrating or not?

iPhone - How do I know if the vibrate is on or off for iOS?

iPhone Vibration

Making the iPhone Vibration

Detecting the iPhone's Ring / Silent / Mute switch using AVAudioPlayer not working?

【讨论】:

  • 不要发布一组重复的链接,而是投票关闭问题作为重复。
  • 好的兄弟我会的。
  • @user3182143,你能帮我看看如何使用 AVAudiosession 来检查系统振动是打开还是关闭,而不是我实现的代码?
猜你喜欢
  • 1970-01-01
  • 2011-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多