새소식

🏫 Mobile/🤖 Cordova

[iOS] How to solve Canvas toDataurl CORS

728x90

🔥 Question

👉 [Error] Origin null is not allowed by Access-Control-Allow-Origin. Status code: 0

um.. Do you use html canvas in WKWebView?

🧙 Solution

👉 You need to modify the CDVWebView Engine yourself.

If the canvas is contaminated, you can solve it this way.

And add the following two lines after it :)

[configuration.preferences setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];
[configuration setValue:@"TRUE" forKey:@"allowUniversalAccessFromFileURLs"];

 

like this!

- (WKWebViewConfiguration*) createConfigurationFromSettings:(NSDictionary*)settings
{
    WKWebViewConfiguration* configuration;
    if (_configuration) {
        configuration = _configuration;
    } else {
        configuration = [[WKWebViewConfiguration alloc] init];
        configuration.processPool = [[CDVWebViewProcessPoolFactory sharedFactory] sharedProcessPool];
        [configuration.preferences setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];
        [configuration setValue:@"TRUE" forKey:@"allowUniversalAccessFromFileURLs"];
    }
  
  ...
 

🧭 References

[1] reference : https://stackoverflow.com/questions/36000757/cordova-ios-error-origin-null-is-not-allowed-by-access-control-allow-origin

 

If I was of any help to you, please buy me coffee 😿😢😥

If you have any questions, please leave them in the comments

 

 

 

반응형
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.