在看到切换后,我编写了一个小切换来启用和禁用振动,它只会在静音模式下停用振动。为此,我在 plist 文件中更改了布尔值,效果很好。我什至可以在 Settings.app 中看到结果。但我的问题是,它会像什么都没发生一样振动。我如何告诉 iPhone,plist 文件中的某些内容发生了变化,但没有重新启动?
请帮我。
ps:当您想查看我的代码时,我已将重要部分复制并粘贴在这里:
void setState(BOOL enable) // required; called when user presses toggle button
{
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist"];
if (enable) // toggle is disabled, so enable it
{
[dict setObject:[NSNumber numberWithBool:YES] forKey:@"ring-vibrate"];
[dict setObject:[NSNumber numberWithBool:YES] forKey:@"silent-vibrate"];
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
else // toggle is enabled, so disable it
{
[dict setObject:[NSNumber numberWithBool:NO] forKey:@"ring-vibrate"];
[dict setObject:[NSNumber numberWithBool:NO] forKey:@"silent-vibrate"];
}
[dict writeToFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist" atomically:YES];
isToggleEnabled = enable; // for getStateFast() use
}