diff --git a/lime/ui/Haptic.hx b/lime/ui/Haptic.hx index cbf824b96..ae85a2f69 100644 --- a/lime/ui/Haptic.hx +++ b/lime/ui/Haptic.hx @@ -2,25 +2,32 @@ package lime.ui; #if android import lime.system.JNI; +#elseif (lime_cffi && !macro) +import lime.system.CFFI; #end class Haptic { - #if android - private static var jni_vibrate:Int->Int->Void = null; + #if ( android || ios ) + private static var __vibrate:Int->Int->Void = null; #end public static function vibrate(period:Int, duration:Int){ #if android - if(jni_vibrate==null){ - jni_vibrate = JNI.createStaticMethod("org/haxe/lime/GameActivity", "vibrate", "(II)V"); + if(__vibrate==null){ + __vibrate = JNI.createStaticMethod("org/haxe/lime/GameActivity", "vibrate", "(II)V"); } try{ // This will raise an exception if you don't have VIBRATE permission - jni_vibrate(period, duration); + __vibrate(period, duration); } catch (e:Dynamic) { trace("JNI Exception: Have you added VIBRATE permission?"); } + #elseif ios + if(__vibrate == null){ + __vibrate = CFFI.load ("lime", "lime_haptic_vibrate", 2); + } + __vibrate(period, duration); #end } diff --git a/project/Build.xml b/project/Build.xml index 71d5a3550..d932d59fb 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -235,6 +235,7 @@ + diff --git a/project/include/ui/Haptic.h b/project/include/ui/Haptic.h new file mode 100644 index 000000000..8e1269f41 --- /dev/null +++ b/project/include/ui/Haptic.h @@ -0,0 +1,21 @@ +#ifndef LIME_UI_HAPTIC_H +#define LIME_UI_HAPTIC_H + + +namespace lime { + + + class Haptic { + + public: + #ifdef IPHONE + static void Vibrate (int period, int duration); + #endif + + }; + + +} + + +#endif \ No newline at end of file diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index ff88d90a8..cf79ecea5 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -696,6 +697,13 @@ namespace lime { } + void lime_haptic_vibrate (int period, int duration) { + + #ifdef IPHONE + Haptic::Vibrate(period, duration); + #endif + + } value lime_image_encode (value buffer, int type, int quality, value bytes) { @@ -1669,6 +1677,7 @@ namespace lime { DEFINE_PRIME1 (lime_gamepad_get_device_name); DEFINE_PRIME2 (lime_gzip_compress); DEFINE_PRIME2 (lime_gzip_decompress); + DEFINE_PRIME2 (lime_haptic_vibrate); DEFINE_PRIME3v (lime_image_data_util_color_transform); DEFINE_PRIME6v (lime_image_data_util_copy_channel); DEFINE_PRIME7v (lime_image_data_util_copy_pixels); diff --git a/project/src/ui/Haptic.mm b/project/src/ui/Haptic.mm new file mode 100644 index 000000000..98a7bf229 --- /dev/null +++ b/project/src/ui/Haptic.mm @@ -0,0 +1,15 @@ +#include + +#import + +namespace lime { + + + void Haptic::Vibrate (int period, int duration) { + + AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); + + } + + +} \ No newline at end of file