【问题标题】:Jssocials not working in UIWebView/WKWebViewJssocials 在 UIWebView/WKWebView 中不起作用
【发布时间】:2018-05-31 10:42:26
【问题描述】:

我想在 iOS 中使用 jssocial 插件,当用户点击来自 UIWebView 的 Facebook、Twitter 或 Instagram 按钮时没有响应,也没有来自 WKWebView 所以,如果有人在 iOS 中实现了它,请指导我它。 任何帮助都将是可观的。谢谢你

【问题讨论】:

    标签: objective-c facebook uiwebview instagram wkwebview


    【解决方案1】:

    如下设置 WKWebView 属性和委托

     WKPreferences *prefs = [WKPreferences new];
    prefs.javaScriptEnabled = YES;
    prefs.javaScriptCanOpenWindowsAutomatically = YES;
    WKWebViewConfiguration *theConfig = [[WKWebViewConfiguration alloc] init];
    theConfig.preferences = prefs;
    webView = [[EasyJSWKWebView alloc] initWithFrame:self.view.bounds
                                           configuration:theConfig
                                withJavascriptInterfaces:interfaces];
        webView.UIDelegate = self;
        webView.navigationDelegate = self;
    
       [webView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        if (@available(iOS 11.0, *)) {
            webView.scrollView.contentInsetAdjustmentBehavior =  UIScrollViewContentInsetAdjustmentNever;
        }
        [webView loadRequest:requestObj];
        [self.view addSubview:webView];
    
    
        - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:  (WKWindowFeatures *)windowFeatures
      {
    ViewPopUp = [[UIView alloc] initWithFrame:self.view.frame];
    [ViewPopUp setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:ViewPopUp];
    UIButton *btnBack = [[UIButton alloc] initWithFrame:CGRectMake(0, 20, 50, 50)];
    [btnBack setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [btnBack addTarget:self action:@selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [ViewPopUp addSubview:btnBack];
    PopUpView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64) configuration:configuration];
     PopUpView.allowsBackForwardNavigationGestures = YES;
    PopUpView.navigationDelegate = self;
    [self.view addSubview:PopUpView];
    return PopUpView;
     }
    

    【讨论】:

      猜你喜欢
      • 2018-11-06
      • 2023-02-17
      • 1970-01-01
      • 1970-01-01
      • 2015-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      相关资源
      最近更新 更多