美文网首页
JSPatch下发笔记9

JSPatch下发笔记9

作者: anny_4243 | 来源:发表于2017-12-22 11:49 被阅读29次

    OC代码:

    -(void)rightBarButtonItemPressed{
        NSString *js = @"document.getElementsByTagName('meta')['Description']['content']";
        UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"neisha_logo"]];
        imageView.hidden=YES;
        [self.view addSubview:imageView];
        UIImage *image=[[SDImageCache sharedImageCache] imageFromDiskCacheForKey:_imageUrl];
            [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            [imageView sd_setImageWithURL:_imageUrl placeholderImage:[UIImage new] andType:3 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
                [self.webView.wkWebView evaluateJavaScript:js completionHandler:^(id _Nullable desc, NSError * _Nullable error) {
                    [[ThirdShareManager sharedInstance] shareItemWithTitle:_title description:desc image:image url:_url controller:self block:nil];
                }];
            }];
    }
    
    

    JS代码:

    rightBarButtonItemPressed: function() {
                var js = "document.getElementsByTagName\('meta')['Description']['content']";
                var imageView = UIImageView.alloc().initWithImage(UIImage.imageNamed("neisha_logo"));
                imageView.setHidden(1);
                self.view().addSubview(imageView);
                var _imageUrl = self.valueForKey("_imageUrl");
                var _url = self.valueForKey("_url");
                var _title = self.valueForKey("_title");
                console.log(_imageUrl);
                var image = SDImageCache.sharedImageCache().imageFromDiskCacheForKey(_imageUrl);
                MBProgressHUD.showHUDAddedTo_animated(self.view(), 1);
                imageView.sd__setImageWithURL_placeholderImage_andType_completed(_imageUrl, UIImage.new(), 3, block("void, UIImage*, NSError*, SDImageCacheType, NSURL*", function(image, error, cacheType, imageURL) {
                    console.log(image);
                    MBProgressHUD.hideAllHUDsForView_animated(self.view(), 1);
                    self.webView().wkWebView().evaluateJavaScript_completionHandler(js, block("void, id, NSError", function(desc, error) {
                    ThirdShareManager.sharedInstance().shareItemWithTitle_description_image_url_controller_block(_title, desc, image, _url, self, null);
                    }));
                }));
                }
    

    注:
    OC中的字符串@"document.getElementsByTagName('meta')['Description']['content']"; 在JS中要写成"document.getElementsByTagName('meta')['Description']['content']";
    ()前面要加上转义字符\

    相关文章

      网友评论

          本文标题:JSPatch下发笔记9

          本文链接:https://www.haomeiwen.com/subject/qeutgxtx.html