7

我正在尝试将 youtube 视频嵌入到我的 iOS 应用程序中。为此,我创建了一个UIWebView & 尝试从以下位置Youtube加载视频

我已经完成了上述问题的所有答案。即使那样它也不起作用。我也尝试过加载非常简单的 HTML

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

即使那样,我也收到编译错误Parse Issue Expecte ']'

我尝试过清理、退出 XCode 并再次重新启动它。我不知道,我无法使用该方法。如何将上述loadHTMLString方法用于我的UIWebView.

PS:请不要将此问题标记为重复。我已经尝试了Stackoverflow. 没有任何工作

4

6 回答 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];
于 2013-09-19T08:51:02.423 回答
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;
}
于 2015-03-12T07:36:46.900 回答
1

这很简单。您只需要添加一行。试试看:

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];
于 2015-05-22T10:04:06.510 回答
0

这似乎不是 webview 的问题。请在它中断的地方添加代码。错误说你错过了]代码中的某个地方

于 2013-06-17T20:15:03.017 回答
0

如果您希望人们帮助您,您可能需要提供更多代码。我只是以类似的方式使用了 webView,它工作正常。

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

你能提供更多信息和代码吗?

于 2013-06-17T19:49:21.353 回答
-2

尝试将 url 直接加载到 webview 中:

 UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(100, 100, 200, 250)];

[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://youtube.com/embed/-0Xa4bHcJu8"]]];
于 2015-10-12T05:33:53.033 回答