tradingview / charting-library-examples

Examples of Charting Library integrations with other libraries, frameworks and data transports
MIT License
1.33k stars 744 forks source link

Not able to Load Index.html From Local URL present in Xcode project #213

Closed ghost closed 2 years ago

ghost commented 3 years ago

Hi Team, We are currently facing issue when we try to load URL (Index.htlm) from Xcode project locally. we are able to get URL (Load from Bundle) but the screen is blank.

but as in the demo URL i am able to load the chart.

Here is my Code

class ViewController: UIViewController {

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        let frame = UIScreen.main.bounds;

        let configuration = WKWebViewConfiguration()
        configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")
        configuration.preferences.javaScriptEnabled = true
        let urlRaw = Bundle.main.url(forResource: "index", withExtension: "html")

        let webView = WKWebView(frame: frame, configuration: configuration)
        guard let url = urlRaw else {
            print("No file at url")
            return
        }
        print(url)
        webView.loadFileURL(url, allowingReadAccessTo: url)

        view.addSubview(webView)
    }

}

Here is my Index.html File :

<!DOCTYPE html>
<html>
    <head>

        <title>TradingView Charting Library demo</title>

        <!-- Fix for iOS Safari zooming bug -->
        <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="IE=Edge">

        <script type="text/javascript" src="charting_library/charting_library.standalone.js"></script>
        <script type="text/javascript" src="datafeeds/udf/dist/polyfills.js"></script>
        <script type="text/javascript" src="datafeeds/udf/dist/bundle.js"></script>

        <script type="text/javascript">

            function getParameterByName(name) {
                name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
                var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
                    results = regex.exec(location.search);
                return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
            }

            function initOnReady() {
                var widget = window.tvWidget = new TradingView.widget({
                    // debug: true, // uncomment this line to see Library errors and warnings in the console
                    fullscreen: true,
                    symbol: 'AAPL',
                    interval: '1D',
                    container_id: "tv_chart_container",

                    //  BEWARE: no trailing slash is expected in feed URL
                    datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo_feed.tradingview.com"),
                    library_path: "charting_library/",
                    locale: getParameterByName('lang') || "en",

                    disabled_features: ["use_localstorage_for_settings"],
                    enabled_features: ["study_templates"],
                    charts_storage_url: 'https://saveload.tradingview.com',
                    charts_storage_api_version: "1.1",
                    client_id: 'tradingview.com',
                    user_id: 'public_user_id',
                    theme: getParameterByName('theme'),
                });
            };

            window.addEventListener('DOMContentLoaded', initOnReady, false);
        </script>

    </head>

    <body style="margin:0px;">
        <div id="tv_chart_container"></div>
    </body>

</html>

Please let me know what i am doing wrong and share me the possible solution

timocov commented 3 years ago

@makedonsky94 can you please take a look?

makedonsky94 commented 3 years ago

I guess there an issue with SSL certificates as we faced on iOS devices.

Replace

datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo_feed.tradingview.com")

with

datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo-feed-data.tradingview.com")
timocov commented 3 years ago

https://bugs.webkit.org/show_bug.cgi?id=221953

ghost commented 3 years ago

Hi Alexandr I have changed the Datafeed url but still blank screen Coming no error! Please Provide me any link for implementing trading chart view in iOS.

Thanks

On Fri, Feb 19, 2021 at 7:11 PM Alexandr Nevyantsev < notifications@github.com> wrote:

I guess there an issue with SSL certificates as we faced on iOS devices.

Replace

datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo_feed.tradingview.com")

with

datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo-feed-data.tradingview.com")

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tradingview/charting-library-examples/issues/213#issuecomment-782082071, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARWKQB3BZ6DK7TPUG2OSSG3S7ZS7HANCNFSM4XZ5DKYA .

makedonsky94 commented 3 years ago

Can you check the error in Safari Web Inspector?

After the first open, Web Inspector won't have any error messages. You should click on reload button

ghost commented 3 years ago

Hi Team I Tried Everything Getting this message Example[6375:237761] [Process] 0x7fc89701be20 - [pageProxyID=6, webPageID=7, PID=6382] WebPageProxy::didFailProvisionalLoadForFrame: frameID = 3, domain = NSURLErrorDomain, code = -1100 please Help Team

RaviRanjan-11 commented 3 years ago
<!DOCTYPE html>
<html>
    <head>

        <title>TradingView Charting Library demo</title>

        <!-- Fix for iOS Safari zooming bug -->
        <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
            <meta http-equiv="X-UA-Compatible" content="IE=Edge">
                <h1>Exchange Heading</h1>
                <p>Exchanege Paragraph</p>
                </head>

    <body style="margin:0px;">
        <div id="tv_chart_container"></div>
    </body>

</html>

<!---->
<!--<!DOCTYPE html>-->
<!--<html>-->
<!--    <head>-->
<!---->
<!--        <title>TradingView Charting Library demo</title>-->
<!---->
<!--        <!-- Fix for iOS Safari zooming bug -->-->
<!--        <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">-->
<!--        <meta http-equiv="X-UA-Compatible" content="IE=Edge">-->
<!---->
<!--        <script type="text/javascript" src="charting_library/charting_library.standalone.js"></script>-->
<!--        <script type="text/javascript" src="datafeeds/udf/dist/polyfills.js"></script>-->
<!--        <script type="text/javascript" src="datafeeds/udf/dist/bundle.js"></script>-->
<!---->
<!--        <script type="text/javascript">-->
<!---->
<!--            function getParameterByName(name) {-->
<!--                name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");-->
<!--                var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),-->
<!--                    results = regex.exec(location.search);-->
<!--                return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));-->
<!--            }-->
<!---->
<!--            function initOnReady() {-->
<!--                var widget = window.tvWidget = new TradingView.widget({-->
<!--                    // debug: true, // uncomment this line to see Library errors and warnings in the console-->
<!--                    debug: true,-->
<!--                    fullscreen: true,-->
<!--                    symbol: 'AAPL',-->
<!--                    interval: '1D',-->
<!--                    container_id: "tv_chart_container",-->
<!---->
<!--                    //  BEWARE: no trailing slash is expected in feed URL-->
<!--                    datafeed: new Datafeeds.UDFCompatibleDatafeed("demo-feed-data.tradingview.com"),-->
<!--                    library_path: "charting_library",-->
<!--                    locale: getParameterByName('lang') || "en",-->
<!---->
<!--                    disabled_features: ["use_localstorage_for_settings"],-->
<!--                    enabled_features: ["study_templates"],-->
<!--                    charts_storage_url: 'https://saveload.tradingview.com',-->
<!--                    charts_storage_api_version: "1.1",-->
<!--                    client_id: 'tradingview.com',-->
<!--                    user_id: 'public_user_id',-->
<!--                    theme: getParameterByName('theme'),-->
<!--                });-->
<!--            };-->
<!---->
<!--            window.addEventListener('DOMContentLoaded', initOnReady, false);-->
<!--        </script>-->
<!---->
<!--    </head>-->
<!---->
<!--    <body style="margin:0px;">-->
<!--        <div id="tv_chart_container"></div>-->
<!--    </body>-->
<!---->
<!--</html>-->

We are able to load other URL eg. the webpage where we have implemented trading view as well even this above code of heading and para works fine but the comented code is not working.

makedonsky94 commented 3 years ago

@veerChauhan I found that the code from your example does not working properly.

There you need to change

library_path: "charting_library" to library_path: "charting_library/"

makedonsky94 commented 3 years ago

@ShashankOodles1 That means there something bad happened in requests to local files. But I can't reproduce the bug with your example. Guess I'm using the different version of charting library. I need the error from Web Inspector. You can find it in Safari browser image

ghost commented 3 years ago

@makedonsky94 Do have any demo for implementation of ios trading chart view.

makedonsky94 commented 3 years ago

https://github.com/tradingview/charting-library-examples/tree/master/ios-swift It was tested with the last version of charting library. If you have any troubles with this example please let us know what errors do you have in the Safari Web Inspector

ghost commented 3 years ago

Screenshot 2021-03-02 at 5 04 34 PM <!DOCTYPE HTML>

TradingView Charting Library demo
makedonsky94 commented 3 years ago
<script type="text/javascript" src="charting_library.standalone.js"></script>

In which folder the js file do you have? As I can see in the previous code example you had src="charting_library/charting_library.standalone.js"

Also, you have incorrect domain name in datafeed url. Replace

datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo_feed_data.tradingview.com"),

with

datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo-feed-data.tradingview.com"),

In the row

const widgetOptions = ({

you should call

const widgetOptions = window.tvWidget = new TradingView.widget({

Please, check your code and try to run

ghost commented 3 years ago

Screenshot 2021-03-02 at 9 05 53 PM Screenshot 2021-03-02 at 9 07 14 PM <!DOCTYPE HTML>

TradingView Charting Library demo

I followed what you said now i have send you everything please check

ghost commented 3 years ago

@makedonsky94 please see and help

makedonsky94 commented 3 years ago

Yep, the document can't load js library. So you got that error

Replace

    <script type="text/javascript" src="charting_library.standalone.js"></script>

with

    <script type="text/javascript" src="charting_library/charting_library.standalone.js"></script>
ghost commented 3 years ago

Screenshot 2021-03-02 at 9 17 48 PM

ghost commented 3 years ago

Screenshot 2021-03-02 at 9 19 18 PM

ghost commented 3 years ago

Screenshot 2021-03-02 at 9 20 37 PM in my charting Library i have two files same name so i used legacy system does it change cause any error Screenshot 2021-03-02 at 9 21 04 PM

ghost commented 3 years ago

file:///Users/shashankmishra/Desktop/ios-swift/App/ChartingLibrary/charting_library/index.html this is the url when i drag my index file to safari browser

makedonsky94 commented 3 years ago

Please, check your bundles. You should keep nesting of folders image

ghost commented 3 years ago

Screenshot 2021-03-02 at 10 37 53 PM still getting this

ghost commented 3 years ago

Screenshot 2021-03-02 at 10 41 38 PM Screenshot 2021-03-02 at 10 41 50 PM

makedonsky94 commented 3 years ago

https://github.com/tradingview/charting-library-examples/issues/213#issuecomment-789006933 At this screenshot the library loaded successfully. You broke something. Check the paths carefully

ghost commented 3 years ago

@makedonsky94 chart is coming on safari but won't able to run on device by dragging my index.html to safari

ghost commented 3 years ago

Screenshot 2021-03-02 at 11 57 08 PM this is coming in safari

ghost commented 2 years ago

Hi @makedonsky94 i have implemented trading chart in Local Project but i am not able to change symbol as it is not accessible form function initOnReady() { const widgetOptions = window.tvWidget = new TradingView.widget({ // debug: true, // uncomment this line to see Library errors and warnings in the console fullscreen: true, symbol: '14', interval: '1D', container_id: "tv_chart_container", so can you let me know how i can make symbol accessible and make dynamic

neerajk207 commented 2 years ago

Hi @makedonsky94 i have implemented trading chart in Local Project but i am not able to change symbol as it is not accessible form function initOnReady() { const widgetOptions = window.tvWidget = new TradingView.widget({ // debug: true, // uncomment this line to see Library errors and warnings in the console fullscreen: true, symbol: '14', interval: '1D', container_id: "tv_chart_container", so can you let me know how i can make symbol accessible and make dynamic

@ShashankOodles1 were you able to make the symbol dynamic? if yes, please let me know.

ghost commented 2 years ago

yes @neerajk207 you just have to replace symbol in index file by sending via webview property let share you screen shot and let me if issue still persists note :- selected chart id which is dynamic on your screen your viewcontroller Screenshot 2022-03-30 at 12 52 25 AM index.html Screenshot 2022-03-30 at 12 51 40 AM

salman-ar-sar commented 1 year ago

@timocov @ShashankOodles1 I am working on integrating TradingView into my react native app. I have put the library into it. It is working fine in android and iOS 15 and above. But on iOS 14 I am getting a blank screen with no error in metro. When I tried to debug using Safari inspector I am getting this error: Failed to load resource: The operation couldn’t be completed. (WebKitBlobResource error 1.) Any idea what could be the issue and how to solve it?