Failed to load html string in UIWebView using loadHTMLString: baseURL in iOS?

I am trying to insert a youtube video into my iOS application. To do this, I created a UIWebView and tried to download Youtube videos from here

I reviewed all the answers to the above problem. Even then it does not work. I also tried loading very simple HTML

  NSString *embedHTML =[NSString stringWithFormat:@"<html><body>Hello World</body></html>"]; [webView loadHTMLString:embedHTML baseURL:nil]; 

Even then I get a compilation error Parse Issue Expecte ']'

I tried to clear by exiting Xcode and restarting it again. I do not know, I can not use this method. How to use the loadHTMLString method loadHTMLString for my UIWebView .

PS: Please do not post this question as a duplicate. I tried all the solutions in Stackoverflow . Nothing worked

+6
source share
6 answers
 WebView *webDesc = [[UIWebView alloc]initWithFrame:CGRectMake(12, 50, 276, 228)]; NSString *embedHTML = @"<html><head></head><body><p>1. You agree that you will be the technician servicing this work order?.<br>2. You are comfortable with the scope of work on this work order?.<br>3. You understand that if you go to site and fail to do quality repair for any reason, you will not be paid?.<br>4. You must dress business casual when going on the work order.</p></body></html>"; webDesc.userInteractionEnabled = NO; webDesc.opaque = NO; webDesc.backgroundColor = [UIColor clearColor]; [webDesc loadHTMLString: embedHTML baseURL: nil]; 
+5
source
 - (NSString *)getHTMLContent { NSString *cssPath = [[NSBundle mainBundle] pathForResource:@"baseline" ofType:@"css"]; NSData *cssData = [NSData dataWithContentsOfFile:cssPath]; NSString *cssStyle = [[NSString alloc] initWithData:cssData encoding:NSASCIIStringEncoding]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; NSString *subtitle = [NSString stringWithFormat:@"%@ | %@", self.article.author, [dateFormatter stringFromDate:self.article.publishedDate]]; NSString *htmlString = [NSString stringWithFormat:@"<html><head><meta name='viewport' content='width=device-width; initial-scale=1.0; maximum-scale=1.0;'></head><style type=\"text/css\">%@</style><body><div id=\"container\"><h1>%@</h1><p class='subtitle'>%@</p>%@</div></body></html>", cssStyle, self.article.title, subtitle, self.article.content]; return htmlString; } 
+1
source

It is very simple. You must add only one line. And here it is. Try

  NSString *htmlString = @"<html><head></head><body><p>1. You agree that you will be the technician servicing this work order?.<br>2. You are comfortable with the scope of work on this work order?.<br>3. You understand that if you go to site and fail to do quality repair for any reason, you will not be paid?.<br>4. You must dress business casual when going on the work order.</p></body></html>"; [WebView loadHTMLString: htmlString baseURL: nil]; 
+1
source

You probably need to provide more code if you want people to help you. I just used webView in a similar way and works great.

 self.webView = [[UIWebView alloc] initWithFrame:myFrame]; self.webView.scalesPageToFit = YES; [self.webView setBackgroundColor:[UIColor whiteColor]]; //pass the string to the webview [self.webView loadHTMLString:[[self.itineraryArray objectAtIndex:indexPath.row] valueForKey:@"body"] baseURL:nil]; //add it to the subview [self.view addSubview:self.webView]; 

Can you provide additional information and code?

0
source

This does not seem to be a problem in webview. Please add the code where it breaks.Error says what you missed ] somewhere in the code

0
source

try loading the URL directly into the webview:

  UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(100, 100, 200, 250)]; [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://youtube.com/embed/-0Xa4bHcJu8"]]]; 
-2
source

Source: https://habr.com/ru/post/947498/