当前位置:   article > 正文

cocos jsb调用IOS震动功能

cocos jsb调用IOS震动功能

js端代码:

  1. export default class JsbUtils {
  2. public static callVibration(data: any): void {
  3. if (CC_JSB) {
  4. // @ts-ignore
  5. jsb.reflection.callStaticMethod('JsBridge', 'sayMe');
  6. jsb.reflection.callStaticMethod('JsBridge', 'callVibration:', data);
  7. }
  8. }
  9. }
  10. export const jsbUtils = new JsbUtils();

OC: JsBridge.h

  1. #import <Foundation/Foundation.h>
  2. #import <UIKit/UIKit.h>
  3. NS_ASSUME_NONNULL_BEGIN
  4. @interface JsBridge : NSObject
  5. + (void)callVibration:(NSString *)withName;
  6. + (void)sayMe;
  7. @end
  8. NS_ASSUME_NONNULL_END

JsBridge.m

  1. #import "JsBridge.h"
  2. @implementation JsBridge
  3. + (void)callVibration:(NSString *)withName {
  4. NSLog(@"withName is %@",withName);
  5. NSLog(@"hello");
  6. UIImpactFeedbackGenerator* generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium];
  7. [generator impactOccurred];
  8. }
  9. + (void)sayMe {
  10. NSLog(@"sayMe");
  11. }
  12. @end

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/416926
推荐阅读
相关标签
  

闽ICP备14008679号