Skip to content

Commit

Permalink
Merge pull request #16 from MarcoEidinger/master
Browse files Browse the repository at this point in the history
use webViewEngine API to call window.plugins.indexAppContent.onItemPressed
  • Loading branch information
MarcoEidinger authored Apr 24, 2017
2 parents f098b21 + 8d0834a commit 59fc276
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ios/app/AppDelegate+IndexAppContent.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ - (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull N
if ([userActivity.activityType isEqualToString:CSSearchableItemActionType]) {
// Get the item identifier and use it
NSString *identifier = userActivity.userInfo[CSSearchableItemActivityIdentifier];

NSString *jsFunction = @"window.plugins.indexAppContent.onItemPressed";
NSString *params = [NSString stringWithFormat:@"{'identifier':'%@'}", identifier];
NSString *result = [NSString stringWithFormat:@"%@(%@)", jsFunction, params];
[self callJavascriptFunctionWhenAvailable:result];
}

return YES;
}

- (void)callJavascriptFunctionWhenAvailable:(NSString *)function {
IndexAppContent *indexAppContent = [self.viewController getCommandInstance:@"IndexAppContent"];

if (indexAppContent.initDone && indexAppContent.ready) {
[self sendCommand:function webView:indexAppContent.webView];
[self sendCommand:function webViewEngine:indexAppContent.webViewEngine];
} else {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, kCALL_DELAY_MILLISECONDS * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
[self callJavascriptFunctionWhenAvailable:function];
});
}
}

- (void)sendCommand:(NSString *)command webView:(UIWebView *)webView
- (void)sendCommand:(NSString *)command webViewEngine:(id<CDVWebViewEngineProtocol>)webViewEngine
{
[webView stringByEvaluatingJavaScriptFromString:command];
[webViewEngine evaluateJavaScript:command completionHandler:nil];
}

@end

0 comments on commit 59fc276

Please sign in to comment.