From 02c2e68c1c7c0bfefae1fe4644ae3dbafde8abf6 Mon Sep 17 00:00:00 2001 From: wanghualei Date: Sun, 13 Jun 2021 16:32:40 +0800 Subject: [PATCH] add custom event --- Podfile | 4 ++-- demo/ViewController.m | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Podfile b/Podfile index c2ebe50..4c7d13e 100644 --- a/Podfile +++ b/Podfile @@ -4,8 +4,8 @@ platform :ios, "9.0" inhibit_all_warnings! target "demo" do - pod 'FinApplet', '2.28.1' - pod 'FinAppletExt', '2.28.1' + pod 'FinApplet', '2.29.1' + pod 'FinAppletExt', '2.29.1' end diff --git a/demo/ViewController.m b/demo/ViewController.m index a8822aa..3f47525 100644 --- a/demo/ViewController.m +++ b/demo/ViewController.m @@ -59,9 +59,22 @@ @"path" : @"/pages/webview/webview" }; [self.appletList addObject:@{@"appId":@"5fc8934aefb8c600019e9747",@"title":@"自定义H5 API示例", @"startParams":startParams}]; + [self.appletList addObject:@{@"appId":@"60c5bbf99e094f00015079ee",@"title":@"原生向小程序发送事件"}]; [self.tableView reloadData]; } +- (void)sendCustomEvent +{ + if (@available(iOS 10.0, *)) { + NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:3 repeats:YES block:^(NSTimer * _Nonnull timer) { + NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970]; + [[FATClient sharedClient].nativeViewManager sendCustomEventWithDetail:@{@"timestamp":@(timestamp)} completion:^(id result, NSError *error) { + NSLog(@"sendCustomEventW:%@", error); + }]; + }]; + } +} + #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { @@ -91,7 +104,9 @@ NSDictionary *startParams = dict[@"startParams"]; [[FATClient sharedClient] startRemoteApplet:appId startParams:startParams InParentViewController:self completion:^(BOOL result, NSError *error) { - + if ([appId isEqualToString:@"60c5bbf99e094f00015079ee"]) { + [self sendCustomEvent]; + } }]; }