nnhubbard / ZSSRichTextEditor

A beautiful rich text WYSIWYG editor for iOS with a syntax highlighted source view
MIT License
3.78k stars 584 forks source link

insertImage failed! #251

Open sunneytree opened 4 years ago

sunneytree commented 4 years ago

i use insertImage:alt: insert image url like https://stage-fs.lu***Mezx9.jpg . it's can't display . But I'll just write jj in the editor HTML and can load it. how can I solve this problem ?

lovehenggege commented 4 years ago

请问这个问题您有解决了吗

mohamedaslam commented 4 years ago

iam also getting same issue.did you solved this issue??

mariusmaricean commented 4 years ago

I'm struggling also with this.What's the fix? Thx! 😉

morisunshine commented 4 years ago

Solved by change the code in ZSSRichTextEditor.m

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {

    NSString *query = [navigationAction.request.URL query];

    NSString *urlString = [navigationAction.request.URL absoluteString];

//    decisionHandler(WKNavigationActionPolicyAllow);

    NSLog(@"web request");
    NSLog(@"%@", urlString);
    NSLog(@"%@", query);

    if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {

        //On the old UIWebView delegate it returned false Bool here
        //TODO: what should we do now?
        decisionHandler(WKNavigationActionPolicyCancel);

    } else if ([urlString rangeOfString:@"callback://0/"].location != NSNotFound) {

        // We recieved the callback
        NSString *className = [urlString stringByReplacingOccurrencesOfString:@"callback://0/" withString:@""];
        [self updateToolBarWithButtonName:className];

        decisionHandler(WKNavigationActionPolicyCancel);
    } else if ([urlString rangeOfString:@"debug://"].location != NSNotFound) {

        NSLog(@"Debug Found");

        // We recieved the callback
        NSString *debug = [urlString stringByReplacingOccurrencesOfString:@"debug://" withString:@""];
        debug = [debug stringByReplacingPercentEscapesUsingEncoding:NSStringEncodingConversionAllowLossy];
        NSLog(@"%@", debug);

    } else if ([urlString rangeOfString:@"scroll://"].location != NSNotFound) {

        NSInteger position = [[urlString stringByReplacingOccurrencesOfString:@"scroll://" withString:@""] integerValue];
        [self editorDidScrollWithPosition:position];
        decisionHandler(WKNavigationActionPolicyCancel);

    } else {
        decisionHandler(WKNavigationActionPolicyAllow);
    }
}
nnhubbard commented 4 years ago

Can someone submit a pull request for this?

AllisonWangJiaoJiao commented 4 years ago

This solution solved my problem,thank you very much.

Mehul18292 commented 4 years ago

Solution working fine. Project Handler can implement this and close this issue.

sun2483968 commented 4 years ago

这个解决方案解决了我的问题,非常感谢。

如何联系你 QQ 10944809 能加我吗 有些问题需请教

SummerHF commented 4 years ago

Solved by change the code in ZSSRichTextEditor.m

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {

    NSString *query = [navigationAction.request.URL query];

    NSString *urlString = [navigationAction.request.URL absoluteString];

//    decisionHandler(WKNavigationActionPolicyAllow);

    NSLog(@"web request");
    NSLog(@"%@", urlString);
    NSLog(@"%@", query);

    if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {

        //On the old UIWebView delegate it returned false Bool here
        //TODO: what should we do now?
        decisionHandler(WKNavigationActionPolicyCancel);

    } else if ([urlString rangeOfString:@"callback://0/"].location != NSNotFound) {

        // We recieved the callback
        NSString *className = [urlString stringByReplacingOccurrencesOfString:@"callback://0/" withString:@""];
        [self updateToolBarWithButtonName:className];

        decisionHandler(WKNavigationActionPolicyCancel);
    } else if ([urlString rangeOfString:@"debug://"].location != NSNotFound) {

        NSLog(@"Debug Found");

        // We recieved the callback
        NSString *debug = [urlString stringByReplacingOccurrencesOfString:@"debug://" withString:@""];
        debug = [debug stringByReplacingPercentEscapesUsingEncoding:NSStringEncodingConversionAllowLossy];
        NSLog(@"%@", debug);

    } else if ([urlString rangeOfString:@"scroll://"].location != NSNotFound) {

        NSInteger position = [[urlString stringByReplacingOccurrencesOfString:@"scroll://" withString:@""] integerValue];
        [self editorDidScrollWithPosition:position];
        decisionHandler(WKNavigationActionPolicyCancel);

    } else {
        decisionHandler(WKNavigationActionPolicyAllow);
    }
}

get crash