WeAppNativePlugin.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // WeAppNativePlugin.h
  3. // WeAppNativePlugin
  4. //
  5. #import <Foundation/Foundation.h>
  6. #ifndef _WEAPPMODULENATIVEPLUGIN_
  7. #define _WEAPPMODULENATIVEPLUGIN_
  8. NS_ASSUME_NONNULL_BEGIN
  9. typedef void (^WeAppNativePluginCallback)(id _Nullable ret);
  10. @protocol WeAppNativePluginProtocol <NSObject>
  11. #define WEAPP_DEFINE_PLUGIN_ID(plugin_id) \
  12. - (NSString *)pluginId { \
  13. return @#plugin_id; \
  14. } \
  15. #define WEAPP_EXPORT_PLUGIN_METHOD_SYNC(methodName, methodSelector) \
  16. - (void)__weapp_plugin_method_sync__##methodName { \
  17. [self registerSyncMethod:@{ @"methodName": @#methodName, @"selectorName": NSStringFromSelector(methodSelector) }]; \
  18. }
  19. #define WEAPP_EXPORT_PLUGIN_METHOD_ASYNC(methodName, methodSelector) \
  20. - (void)__weapp_plugin_method_async__##methodName { \
  21. [self registerAsyncMethod:@{ @"methodName": @#methodName, @"selectorName": NSStringFromSelector(methodSelector) }]; \
  22. }
  23. @required
  24. - (NSString *) pluginId;
  25. @optional
  26. - (void)initPlugin;
  27. @end
  28. @interface WeAppNativePlugin : NSObject
  29. + (BOOL)registerPluginAndInit:(WeAppNativePlugin *)pluginClassInstance;
  30. - (NSString *)getPluginId;
  31. - (void)registerAsyncMethod:(NSDictionary *)name;
  32. - (void)registerSyncMethod:(NSDictionary *)name;
  33. - (void)registerAppDelegateMethod:(SEL)appMethod;
  34. @end
  35. NS_ASSUME_NONNULL_END
  36. #endif