7

I am trying to embed youtube video into my iOS application.For that I have created a UIWebView & trying to load the Youtube video from following here

I have gone through the all the answers for the above problem. Even then its not working. I have also tried loading very simple HTML

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

Even then, I am getting compile error Parse Issue Expecte ']'

I have tried cleaning, quitting the XCode & relaunching it again. I donno, I am not able to use that method. How to use the above loadHTMLString method for my UIWebView.

PS : Please do not tag this question as duplicate. I have tried all the solutions in Stackoverflow. Nothing has worked

6
  • did everything except debugging? log the frame of webview and please add it here Commented Jun 17, 2013 at 20:11
  • @LithuT.V.. I am not even able to compile the code. Its a compile time error. Commented Jun 17, 2013 at 20:14
  • commenting which line compiles the code? Commented Jun 17, 2013 at 20:15
  • Commenting [webView loadHTMLString:embedHTML baseURL:nil]; line compiles the code perfectly Commented Jun 17, 2013 at 20:20
  • I am getting same error.. how you solved it? Commented Mar 21, 2014 at 9:41

6 Answers 6

5
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];
Sign up to request clarification or add additional context in comments.

Comments

1
- (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;
}

Comments

1

It is very simple. You just have to add only one line. Try It:

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];

Comments

0

You probably need to provide more code if you want people to help you. I just used webView in a similar way and it's working fine.

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 more information and code?

3 Comments

This is what I did UIWebView *webView = [[UIWebView alloc] initWithFrame:myFrame]; NSString *embedHTML =[NSString stringWithFormat:@"<html><body>Hello World</body></html>"]; [webView loadHTMLString:embedHTML baseURL:nil]; Thats it, this is what I did. I am getting compile time error. That loadHTMLString method itself is not working. Even though everything is right, it showing Parse Issue Expecte ']' as compile error
Are you sure the error is from the webView? If you comment out the webView lines, the error disappear? Are you adding the webview to the main view?
Yes. Problem is with webview. If I comment that line, then everything is working fine. Even before adding itself I am getting the error.
0

it doesnt seems like an issue on webview.Please do add the code where it breaks.Error says you missed a ] somewhere in the code

3 Comments

@LithuT.V.. No, not because I left ]. I have even created a new project & there I have written the same line. I dint even copy paste it. I have typed manually everything. Even then same error in other project too :-(
which line you are talking about ??
webview frame please?also check webview has valid memory.connected properly .code seems ok to me
-2

try to load 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"]]];

1 Comment

Answer does not related with question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.