本文主要是介绍cocos jsb调用IOS震动功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
js端代码:
export default class JsbUtils {public static callVibration(data: any): void {if (CC_JSB) {// @ts-ignorejsb.reflection.callStaticMethod('JsBridge', 'sayMe');jsb.reflection.callStaticMethod('JsBridge', 'callVibration:', data);}}}
export const jsbUtils = new JsbUtils();
OC: JsBridge.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN@interface JsBridge : NSObject
+ (void)callVibration:(NSString *)withName;
+ (void)sayMe;
@endNS_ASSUME_NONNULL_END
JsBridge.m
#import "JsBridge.h"@implementation JsBridge
+ (void)callVibration:(NSString *)withName {NSLog(@"withName is %@",withName);NSLog(@"hello");UIImpactFeedbackGenerator* generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium];[generator impactOccurred];
}
+ (void)sayMe {NSLog(@"sayMe");
}
@end
这篇关于cocos jsb调用IOS震动功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!