MyPlugin.mm 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #import <Foundation/Foundation.h>
  2. #import <UIKit/UIKit.h>
  3. #import "WeAppNativePlugin.framework/WeAppNativePlugin.h"
  4. #import "MyPlugin.h"
  5. __attribute__((constructor))
  6. static void initPlugin() {
  7. [MyPlugin registerPluginAndInit:[[MyPlugin alloc] init]];
  8. };
  9. @implementation MyPlugin
  10. // 声明插件ID
  11. WEAPP_DEFINE_PLUGIN_ID(wxf1a06dafa3350688)
  12. // 声明插件同步方法
  13. WEAPP_EXPORT_PLUGIN_METHOD_SYNC(mySyncFunc, @selector(mySyncFunc:))
  14. // 声明插件异步方法
  15. WEAPP_EXPORT_PLUGIN_METHOD_ASYNC(myAsyncFuncwithCallback, @selector(myAsyncFunc:withCallback:))
  16. - (id)mySyncFunc:(NSDictionary *)param {
  17. NSLog(@"mySyncFunc %@", param);
  18. return @"mySyncFunc";
  19. }
  20. - (void)myAsyncFunc:(NSDictionary *)param withCallback:(WeAppNativePluginCallback)callback {
  21. NSLog(@"myAsyncFunc %@", param);
  22. callback(@{ @"a": @"1", @"b": @[@1, @2], @"c": @3 });
  23. }
  24. // 插件初始化方法,在注册插件后会被自动调用
  25. - (void)initPlugin {
  26. NSLog(@"initPlugin");
  27. [self registerAppDelegateMethod:@selector(application:openURL:options:)];
  28. [self registerAppDelegateMethod:@selector(application:continueUserActivity:restorationHandler:)];
  29. }
  30. - (void)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
  31. NSLog(@"url scheme");
  32. }
  33. - (void)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *__nullable restorableObjects))restorationHandler {
  34. NSLog(@"universal link");
  35. }
  36. @end