Search code examples
iphoneobjective-cios6uiwebview

Playing Video on UIWebView getting Access Denied


Hello Everyone i am trying to play video based on URL that i am getting through API but i am getting Error like Access Denied.

The reason why i am playing video in UIWebView is because Video is not the Primary feature in my Application its just for Show Tutorial to the User so i have not used MPMoviePlayerController but if required than i can use.

But i want know the exact reason why such Error occurs in UIWebView.

enter image description here

Any guide or help will be appreciated.

Thanks in Advance.


Solution

  • Add below method to your ViewController.m :

    //This method should get called when you want to add and load the webview

    - (void)loadUIWebView
    {
        UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];  
        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:currentURL]]];
        [self.view addSubview:webView];
        [webView release]; // No need of this line if ARC is implemented in your project
    }
    

    Using Interface Builder-

    • Add a UIWebView object to your interface.
    • Set the "hidden" property to checked (in the "Attributes Inspector" window in Interface Builder). You should keep it hidden until you want to display WebView.
    • Add the following code to your ViewController.h.

      @property (nonatomic, retain) IBOutlet UIWebView *webView;

    • Add the following line below the @synthesize in your ViewController.m

    @synthesize webView;

    • Add [webView release]; in the dealloc method. // No need of this line if ARC is implemented in your project }
    • Go back into IB and click on File's Owner, and connect the webView outlet to the webView you created.
    • Add the following method.

    //This method should get called when you want to add and load the webview

    - (void)loadUIWebView
    {
        [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:currentURL]]];
        self.webView.hidden = NO; 
    }
    

    I hope it will help you.