So in my app, I embed a Youtube video using the following code:
- (void)embedYouTube:(NSString*)url frame:(CGRect)frame {
NSString* embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, fra me.size.height];
if(videoView == nil) {
videoView = [[UIWebView alloc] initWithFrame:frame];
videoView.delegate = self;
[self.view addSubview:videoView];
}
[videoView loadHTMLString:html baseURL:nil];
}
Formatted exactly as shown above. But, I get 11 warnings, all saying:
Backslash and Newline separated by space
So my question is, how can I fix that? I’m not really familiar with HTML so I don’t really know what I can and can’t do with that. Thanks in advance
Edit:
I brought all the HTML onto one line, and it reduced my warnings from 11 to 1, which says
Unknown escape sequence ‘/x20’
and here is what the code looks like with that error:
NSString* embedHTML = @"\ <html><head>\ <style type=\"text/css\">\ body {\ background-color: transparent;\ color: white;\ }\ </style>\ </head><body style=\"margin:0\">\ <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \ width=\"%0.0f\" height=\"%0.0f\"></embed>\ </body></html>";
Although human friendly reading, by actually putting line breaks in there this is essentially breaking your NSString, also make sure you don’t escape new lines, won’t work, try out the following: