【问题标题】:Making Vibrate iPhone when switch on a toggle?打开切换开关时让 iPhone 振动?
【发布时间】:2014-09-20 12:10:01
【问题描述】:

我正在寻找一种在我的调整的 PrefernceBundle 中打开切换开关时添加振动的方法。

这是我的代码的一部分:

    #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>

但我不知道如何在我的代码中使用它们。

谢谢大家!

【问题讨论】:

    标签: ios objective-c iphone theos tweak


    【解决方案1】:

    你可以试试这个:

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

    ViewController.h 
    
    -(IBAction)Vibrate; 
    
    ViewController.m 
    
    #import "ViewController.h" 
    #import "AudioToolbox/AudioToolbox.h" 
    
    @implementation ViewController 
    
    -(IBAction)Vibrate
    { 
       AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); 
    }
    

    【讨论】:

    • 但是有了这个,iPhone什么时候会振动?我想在你启用切换时这样做
    【解决方案2】:

    你需要做你说的同样的事情,只需导入类并将该函数写入你想要振动的地方。

    【讨论】:

    • 您想要按钮振动吗?如果是的话,在你想要的地方应用这个方法,我已经尝试过了,在我的情况下它工作得很好。
    • 我用 uibutton 试试这个
    • 我只是在我的 ViewController.h 文件 AudioToolbox/AudioServices.h 中导入该类,并在按钮单击方法上编写 AudioServicesPlaySystemSound(kSystemSoundID_Vibrate),每当我单击该按钮时,我的 iPhone 就会振动。
    猜你喜欢
    • 2012-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-31
    • 1970-01-01
    • 2011-06-11
    相关资源
    最近更新 更多