Ios 打开拨动开关时使iPhone振动?

Ios 打开拨动开关时使iPhone振动?,ios,objective-c,iphone,theos,tweak,Ios,Objective C,Iphone,Theos,Tweak,我正在寻找一种方法,当你在我的调整的PreferenceBundle中打开一个开关时,添加一个振动 这是我代码的一部分: #define PLIST_PATH @"/var/mobile/Library/Preferences/MyTweak.plist" inline bool GetPrefBool(NSString *key) { return [[[NSDictionary dictionaryWithContentsOfFile:PLIST_PATH] valueForKey

我正在寻找一种方法,当你在我的调整的PreferenceBundle中打开一个开关时,添加一个振动

这是我代码的一部分:

    #define PLIST_PATH @"/var/mobile/Library/Preferences/MyTweak.plist"

inline bool GetPrefBool(NSString *key)
{
return [[[NSDictionary dictionaryWithContentsOfFile:PLIST_PATH] valueForKey:key] boolValue];
}

%hook Config
- (void)setURL:(NSString *)fp8 {
if(GetPrefBool(@"kPatch")) {
fp8 = @"http://abcdef.com";
%orig(fp8);
}
return %orig;
}
%end
我想做的是,当你打开“kPatch”开关时,设备会振动

我知道我需要使用这个:

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
并导入以下内容:

#import <AudioToolbox/AudioServices.h>
#导入
但我不知道如何在我的代码中使用它们

谢谢大家

您可以尝试以下方法:

只需创建一个让设备振动的函数,并将其连接到IBOutlet

ViewController.h 

-(IBAction)Vibrate; 

ViewController.m 

#import "ViewController.h" 
#import "AudioToolbox/AudioToolbox.h" 

@implementation ViewController 

-(IBAction)Vibrate
{ 
   AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); 
}

你需要做和你说的一样的事情,只需导入类并在你想要振动的地方编写函数。

但是有了这个,iPhone什么时候会振动?我想在您启用切换按钮时执行此操作您想启动振动按钮吗?如果是,在你想要的地方应用这个方法,我已经尝试过了,在我的例子中效果很好。我用UIButton尝试过这个方法。我只是在我的ViewController.h文件AudioToolbox/AudioServices.h中导入这个类,然后在button click方法上写AudioServicesPlaySystemSound(ksystemsSoundId\u Vibrate),每当我点击这个按钮,我的iPhone就会震动。