DWKWebView.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // DSWKwebview.h
  3. // dspider
  4. //
  5. // Created by 杜文 on 16/12/28.
  6. // Copyright © 2016年 杜文. All rights reserved.
  7. //
  8. #import <WebKit/WebKit.h>
  9. typedef void (^JSCallback)(NSString * _Nullable result,BOOL complete);
  10. @interface DWKWebView : WKWebView <WKUIDelegate>
  11. @property (nullable, nonatomic, weak) id <WKUIDelegate> DSUIDelegate;
  12. - (void)loadUrl: (NSString * _Nonnull) url;
  13. // Call javascript handler
  14. -(void) callHandler:(NSString * _Nonnull) methodName arguments:(NSArray * _Nullable) args;
  15. -(void) callHandler:(NSString * _Nonnull) methodName completionHandler:(void (^ _Nullable)(id _Nullable value))completionHandler;
  16. -(void) callHandler:(NSString * _Nonnull) methodName arguments:(NSArray * _Nullable) args completionHandler:(void (^ _Nullable)(id _Nullable value))completionHandler;
  17. // set a listener for javascript closing the current page.
  18. - (void)setJavascriptCloseWindowListener:(void(^_Nullable)(void))callback;
  19. /**
  20. * Add a Javascript Object to dsBridge with namespace.
  21. * @param object
  22. * which implemented the javascript interfaces
  23. * @param nativeNamespace
  24. * if empty, the object have no namespace.
  25. **/
  26. - (void)addJavascriptObject:(id _Nullable ) object namespace:(NSString * _Nullable)nativeNamespace;
  27. // Remove the Javascript Object with the supplied namespace
  28. - (void)removeJavascriptObject:(NSString * _Nullable) nativeNamespace;
  29. // Test whether the handler exist in javascript
  30. - (void) hasJavascriptMethod:(NSString * _Nonnull) handlerName methodExistCallback:(void(^ _Nullable)(bool exist))callback;
  31. // Set debug mode. if in debug mode, some errors will be prompted by a dialog
  32. // and the exception caused by the native handlers will not be captured.
  33. - (void) setDebugMode:(bool) debug;
  34. - (void) disableJavascriptDialogBlock:(bool) disable;
  35. // custom the label text of javascript dialog that includes alert/confirm/prompt
  36. - (void) customJavascriptDialogLabelTitles:(NSDictionary*_Nullable) dic;
  37. // private method, the developer shoudn't call this method
  38. - (id _Nullable ) onMessage:(NSDictionary *_Nonnull) msg type:(int) type;
  39. @end