WeAppNativePlugin.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. - (void)sendMiniPluginEvent:(NSDictionary *)param;
  35. @end
  36. NS_ASSUME_NONNULL_END
  37. #endif